@atlure/ui 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlure/ui",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Atlure React Native component library: NativeWind primitives built on @atlure/tokens, shipped as untranspiled TypeScript source",
5
5
  "license": "MIT",
6
6
  "author": "David Moreira",
@@ -37,9 +37,9 @@
37
37
  "class-variance-authority": "0.7.1",
38
38
  "clsx": "2.1.1",
39
39
  "tailwind-merge": "2.6.0",
40
- "@atlure/icons": "0.6.1",
41
- "@atlure/tokens": "0.6.1",
42
- "@atlure/types": "0.6.1"
40
+ "@atlure/icons": "0.7.0",
41
+ "@atlure/tokens": "0.7.0",
42
+ "@atlure/types": "0.7.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "nativewind": "^4.2.6",
@@ -11,11 +11,23 @@ export const urgencyBadgeVariant: Record<Urgency, BadgeVariant> = {
11
11
  high: "destructive",
12
12
  };
13
13
 
14
+ export const DEFAULT_URGENCY_LABELS: Record<Urgency, string> = {
15
+ low: "Low priority",
16
+ medium: "Normal",
17
+ high: "High priority",
18
+ };
19
+
14
20
  export interface UrgencyBadgeProps extends Omit<BadgeProps, "label" | "variant"> {
15
21
  urgency: Urgency;
16
- label: string;
22
+ label?: string;
17
23
  }
18
24
 
19
- export function UrgencyBadge({ urgency, ...badgeProps }: UrgencyBadgeProps) {
20
- return <Badge variant={urgencyBadgeVariant[urgency]} {...badgeProps} />;
25
+ export function UrgencyBadge({ urgency, label, ...badgeProps }: UrgencyBadgeProps) {
26
+ return (
27
+ <Badge
28
+ variant={urgencyBadgeVariant[urgency]}
29
+ label={label ?? DEFAULT_URGENCY_LABELS[urgency]}
30
+ {...badgeProps}
31
+ />
32
+ );
21
33
  }
@@ -12,19 +12,21 @@ import { Button } from "../button/button";
12
12
  import { Text } from "../text/text";
13
13
 
14
14
  export interface ErrorStateProps extends Omit<ViewProps, "children"> {
15
- title: string;
16
- message: string;
17
- retryLabel: string;
15
+ title?: string;
16
+ message?: string;
17
+ retryLabel?: string;
18
18
  onRetry: () => void;
19
19
  icon?: ReactNode;
20
+ retryTestID?: string;
20
21
  }
21
22
 
22
23
  export function ErrorState({
23
- title,
24
+ title = "Something went wrong",
24
25
  message,
25
- retryLabel,
26
+ retryLabel = "Retry",
26
27
  onRetry,
27
28
  icon,
29
+ retryTestID,
28
30
  className,
29
31
  ...viewProps
30
32
  }: ErrorStateProps) {
@@ -34,11 +36,13 @@ export function ErrorState({
34
36
  <Text accessibilityRole="header" variant="h3" className={stateTextClassName}>
35
37
  {title}
36
38
  </Text>
37
- <Text variant="bodySm" tone="muted" className={stateTextClassName}>
38
- {message}
39
- </Text>
39
+ {message !== undefined ? (
40
+ <Text variant="bodySm" tone="muted" className={stateTextClassName}>
41
+ {message}
42
+ </Text>
43
+ ) : null}
40
44
  <View className={stateActionClassName}>
41
- <Button variant="secondary" label={retryLabel} onPress={onRetry} />
45
+ <Button variant="secondary" label={retryLabel} onPress={onRetry} testID={retryTestID} />
42
46
  </View>
43
47
  </View>
44
48
  );
@@ -1,4 +1,5 @@
1
1
  import { iconSize, Search, X } from "@atlure/icons";
2
+ import { useState } from "react";
2
3
  import { Pressable } from "react-native";
3
4
 
4
5
  import { touchTargetHitSlop } from "../../lib/touch-target";
@@ -8,42 +9,57 @@ import { useDebouncedCallback } from "./hooks/use-debounced-callback";
8
9
 
9
10
  export interface SearchBarProps
10
11
  extends Omit<InputProps, "leadingIcon" | "trailingIcon" | "isMultiline" | "value"> {
11
- value: string;
12
- onChangeText: (value: string) => void;
12
+ value?: string;
13
+ defaultValue?: string;
14
+ onChangeText?: (value: string) => void;
13
15
  onChangeDebounced?: (value: string) => void;
16
+ onCommit?: (value: string) => void;
14
17
  debounceMs?: number;
15
18
  clearAccessibilityLabel: string;
16
19
  }
17
20
 
18
21
  export function SearchBar({
19
22
  value,
23
+ defaultValue,
20
24
  onChangeText,
21
25
  onChangeDebounced,
26
+ onCommit,
22
27
  debounceMs = 300,
23
28
  clearAccessibilityLabel,
24
29
  ...inputProps
25
30
  }: SearchBarProps) {
26
- const { schedule, flush } = useDebouncedCallback(onChangeDebounced, debounceMs);
31
+ const isUncontrolled = defaultValue !== undefined;
32
+ const [draft, setDraft] = useState(defaultValue ?? "");
33
+ const currentValue = isUncontrolled ? draft : (value ?? "");
34
+
35
+ const debouncedTarget = isUncontrolled ? onCommit : onChangeDebounced;
36
+ const { schedule, flush } = useDebouncedCallback(debouncedTarget, debounceMs);
27
37
 
28
38
  const handleChangeText = (nextValue: string) => {
29
- onChangeText(nextValue);
39
+ if (isUncontrolled) {
40
+ setDraft(nextValue);
41
+ }
42
+ onChangeText?.(nextValue);
30
43
  schedule(nextValue);
31
44
  };
32
45
 
33
46
  const handleClear = () => {
34
- onChangeText("");
47
+ if (isUncontrolled) {
48
+ setDraft("");
49
+ }
50
+ onChangeText?.("");
35
51
  flush("");
36
52
  };
37
53
 
38
54
  return (
39
55
  <Input
40
- value={value}
56
+ value={currentValue}
41
57
  onChangeText={handleChangeText}
42
58
  returnKeyType="search"
43
59
  clearButtonMode="never"
44
60
  leadingIcon={<Search size={iconSize.md} className={searchBarIconClassName} />}
45
61
  trailingIcon={
46
- value.length > 0 ? (
62
+ currentValue.length > 0 ? (
47
63
  <Pressable
48
64
  accessibilityRole="button"
49
65
  accessibilityLabel={clearAccessibilityLabel}
@@ -27,21 +27,61 @@ import {
27
27
  SHEET_PAN_ACTIVATION_DISTANCE,
28
28
  } from "./utils";
29
29
 
30
+ export type SheetVariant = "snap" | "modal-slide";
31
+
30
32
  export interface SheetProps {
31
33
  isOpen: boolean;
32
34
  onClose: () => void;
33
- backdropAccessibilityLabel: string;
35
+ backdropAccessibilityLabel?: string;
34
36
  accessibilityLabel?: string;
35
37
  snapPoints?: readonly number[];
36
38
  bottomInset?: number;
39
+ variant?: SheetVariant;
37
40
  className?: string;
38
41
  children: ReactNode;
39
42
  }
40
43
 
41
- export function Sheet({
44
+ export function Sheet(props: SheetProps) {
45
+ if (props.variant === "modal-slide") {
46
+ return <ModalSlideSheet {...props} />;
47
+ }
48
+
49
+ return <SnapSheet {...props} />;
50
+ }
51
+
52
+ function ModalSlideSheet({
53
+ isOpen,
54
+ onClose,
55
+ backdropAccessibilityLabel = "Close sheet",
56
+ accessibilityLabel,
57
+ className,
58
+ children,
59
+ }: SheetProps) {
60
+ return (
61
+ <Modal visible={isOpen} transparent animationType="slide" onRequestClose={onClose}>
62
+ <View className={sheetContainerClassName}>
63
+ <Pressable
64
+ accessibilityRole="button"
65
+ accessibilityLabel={backdropAccessibilityLabel}
66
+ className={sheetBackdropClassName}
67
+ onPress={onClose}
68
+ />
69
+ <View
70
+ accessibilityViewIsModal
71
+ accessibilityLabel={accessibilityLabel}
72
+ className={cn(sheetContentClassName, className)}
73
+ >
74
+ {children}
75
+ </View>
76
+ </View>
77
+ </Modal>
78
+ );
79
+ }
80
+
81
+ function SnapSheet({
42
82
  isOpen,
43
83
  onClose,
44
- backdropAccessibilityLabel,
84
+ backdropAccessibilityLabel = "Close sheet",
45
85
  accessibilityLabel,
46
86
  snapPoints = DEFAULT_SHEET_SNAP_POINTS,
47
87
  bottomInset = 0,
@@ -26,10 +26,11 @@ export function starFillAt(starNumber: number, value: number): StarFill {
26
26
  }
27
27
 
28
28
  export interface StarRatingProps extends Omit<ViewProps, "children"> {
29
- value: number;
29
+ value: number | null;
30
30
  max?: number;
31
31
  size?: StarRatingSize;
32
32
  showValue?: boolean;
33
+ count?: number;
33
34
  isInteractive?: boolean;
34
35
  onChange?: (value: number) => void;
35
36
  rateAccessibilityLabel?: (starNumber: number, max: number) => string;
@@ -40,6 +41,7 @@ export function StarRating({
40
41
  max = 5,
41
42
  size = "md",
42
43
  showValue = false,
44
+ count,
43
45
  isInteractive = false,
44
46
  onChange,
45
47
  rateAccessibilityLabel = (starNumber, total) => `Rate ${starNumber} out of ${total}`,
@@ -49,15 +51,18 @@ export function StarRating({
49
51
  }: StarRatingProps) {
50
52
  const starNumbers = Array.from({ length: max }, (_, index) => index + 1);
51
53
  const pixelSize = starRatingIconSize[size];
54
+ const hasValue = value !== null;
55
+ const effectiveValue = hasValue ? value : 0;
56
+ const showCount = hasValue && typeof count === "number" && count >= 0;
52
57
 
53
58
  return (
54
59
  <View
55
- accessibilityLabel={accessibilityLabel ?? `${value} out of ${max}`}
60
+ accessibilityLabel={accessibilityLabel ?? (hasValue ? `${value} out of ${max}` : "Not rated")}
56
61
  className={cn(starRatingClassName, className)}
57
62
  {...viewProps}
58
63
  >
59
64
  {starNumbers.map((starNumber) => {
60
- const fill = starFillAt(starNumber, value);
65
+ const fill = starFillAt(starNumber, effectiveValue);
61
66
  const isPainted = fill !== "empty";
62
67
  const StarGlyph = fill === "half" ? StarHalf : Star;
63
68
 
@@ -90,9 +95,12 @@ export function StarRating({
90
95
  </Pressable>
91
96
  );
92
97
  })}
93
- {showValue ? (
98
+ {showValue && hasValue ? (
94
99
  <Text className={starRatingValueVariants({ size })}>{value.toFixed(1)}</Text>
95
100
  ) : null}
101
+ {showCount ? (
102
+ <Text className={starRatingValueVariants({ size })}>{`(${count})`}</Text>
103
+ ) : null}
96
104
  </View>
97
105
  );
98
106
  }