@atlure/ui 0.6.1 → 0.8.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.8.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.8.0",
41
+ "@atlure/tokens": "0.8.0",
42
+ "@atlure/types": "0.8.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
  }
@@ -10,11 +10,38 @@ import {
10
10
  } from "../../variants/state-variants";
11
11
  import { Text } from "../text/text";
12
12
 
13
- export interface EmptyStateProps extends Omit<ViewProps, "children"> {
13
+ export type EmptyStatePreset = "no-results" | "no-filters" | "no-radius";
14
+
15
+ export interface EmptyStateCopy {
14
16
  title: string;
17
+ message: string;
18
+ actionLabel: string;
19
+ }
20
+
21
+ export const DEFAULT_EMPTY_STATE_COPY: Record<EmptyStatePreset, EmptyStateCopy> = {
22
+ "no-results": {
23
+ title: "No matches",
24
+ message: "Nothing matched your query.",
25
+ actionLabel: "Clear search",
26
+ },
27
+ "no-filters": {
28
+ title: "No matches",
29
+ message: "Try loosening your filters.",
30
+ actionLabel: "Clear filters",
31
+ },
32
+ "no-radius": {
33
+ title: "Nobody nearby",
34
+ message: "Try a wider radius.",
35
+ actionLabel: "Widen radius",
36
+ },
37
+ };
38
+
39
+ export interface EmptyStateProps extends Omit<ViewProps, "children"> {
40
+ title?: string;
15
41
  description?: string;
16
42
  icon?: ReactNode;
17
43
  action?: ReactNode;
44
+ preset?: EmptyStatePreset;
18
45
  }
19
46
 
20
47
  export function EmptyState({
@@ -22,18 +49,23 @@ export function EmptyState({
22
49
  description,
23
50
  icon,
24
51
  action,
52
+ preset,
25
53
  className,
26
54
  ...viewProps
27
55
  }: EmptyStateProps) {
56
+ const copy = preset ? DEFAULT_EMPTY_STATE_COPY[preset] : undefined;
57
+ const resolvedTitle = title ?? copy?.title ?? "";
58
+ const resolvedDescription = description ?? copy?.message;
59
+
28
60
  return (
29
61
  <View className={cn(stateLayoutClassName, className)} {...viewProps}>
30
62
  {icon ? <View className={stateIconClassName}>{icon}</View> : null}
31
63
  <Text accessibilityRole="header" variant="h3" className={stateTextClassName}>
32
- {title}
64
+ {resolvedTitle}
33
65
  </Text>
34
- {description ? (
66
+ {resolvedDescription ? (
35
67
  <Text variant="bodySm" tone="muted" className={stateTextClassName}>
36
- {description}
68
+ {resolvedDescription}
37
69
  </Text>
38
70
  ) : null}
39
71
  {action ? <View className={stateActionClassName}>{action}</View> : null}
@@ -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
  );
@@ -3,31 +3,45 @@ import { View, type ViewProps } from "react-native";
3
3
 
4
4
  import { cn } from "../../lib/cn";
5
5
  import { formFieldClassName, formFieldMessageVariants } from "../../variants/form-field-variants";
6
+ import { Input, type InputProps } from "../input/input";
6
7
  import { Label } from "../label/label";
7
8
  import { Text } from "../text/text";
8
9
  import { FormFieldProvider } from "./form-field-context";
9
10
 
10
- export interface FormFieldProps extends Omit<ViewProps, "children"> {
11
+ interface FormFieldSharedProps {
11
12
  label?: string;
12
13
  helperText?: string;
13
14
  error?: string;
14
15
  isRequired?: boolean;
15
16
  isDisabled?: boolean;
16
17
  nativeID?: string;
18
+ }
19
+
20
+ export interface FormFieldContainerProps
21
+ extends FormFieldSharedProps,
22
+ Omit<ViewProps, "children"> {
23
+ variant?: "container";
17
24
  children: ReactNode;
18
25
  }
19
26
 
20
- export function FormField({
21
- label,
22
- helperText,
23
- error,
24
- isRequired = false,
25
- isDisabled = false,
26
- nativeID,
27
- className,
28
- children,
29
- ...viewProps
30
- }: FormFieldProps) {
27
+ export interface FormFieldInlineProps extends FormFieldSharedProps, Omit<InputProps, "children"> {
28
+ variant: "inline";
29
+ inputClassName?: string;
30
+ wrapperClassName?: string;
31
+ }
32
+
33
+ export type FormFieldProps = FormFieldContainerProps | FormFieldInlineProps;
34
+
35
+ export function FormField(props: FormFieldProps) {
36
+ const {
37
+ label,
38
+ helperText,
39
+ error,
40
+ isRequired = false,
41
+ isDisabled = false,
42
+ nativeID,
43
+ } = props;
44
+
31
45
  const generatedID = useId();
32
46
  const controlID = nativeID ?? generatedID;
33
47
  const labelID = `${controlID}-label`;
@@ -35,8 +49,15 @@ export function FormField({
35
49
  const isInvalid = Boolean(error);
36
50
  const message = error ?? helperText;
37
51
 
52
+ const wrapperClassName =
53
+ props.variant === "inline" ? props.wrapperClassName : props.className;
54
+ const outerViewProps = props.variant === "inline" ? undefined : extractOuterViewProps(props);
55
+
56
+ const providedChildren =
57
+ props.variant === "inline" ? renderInline(props) : props.children;
58
+
38
59
  return (
39
- <View className={cn(formFieldClassName, className)} {...viewProps}>
60
+ <View className={cn(formFieldClassName, wrapperClassName)} {...outerViewProps}>
40
61
  {label ? (
41
62
  <Label
42
63
  nativeID={labelID}
@@ -57,7 +78,7 @@ export function FormField({
57
78
  isRequired,
58
79
  }}
59
80
  >
60
- {children}
81
+ {providedChildren}
61
82
  </FormFieldProvider>
62
83
  {message ? (
63
84
  <Text
@@ -72,3 +93,36 @@ export function FormField({
72
93
  </View>
73
94
  );
74
95
  }
96
+
97
+ const SHARED_KEYS = new Set([
98
+ "label",
99
+ "helperText",
100
+ "error",
101
+ "isRequired",
102
+ "isDisabled",
103
+ "nativeID",
104
+ "variant",
105
+ "children",
106
+ "className",
107
+ ]);
108
+
109
+ function extractOuterViewProps(props: FormFieldContainerProps): Omit<ViewProps, "className"> {
110
+ const viewProps: Record<string, unknown> = {};
111
+ for (const [key, value] of Object.entries(props)) {
112
+ if (!SHARED_KEYS.has(key)) {
113
+ viewProps[key] = value;
114
+ }
115
+ }
116
+ return viewProps as Omit<ViewProps, "className">;
117
+ }
118
+
119
+ function renderInline(props: FormFieldInlineProps) {
120
+ const { inputClassName, ...rest } = props;
121
+ const inputProps: Record<string, unknown> = {};
122
+ for (const [key, value] of Object.entries(rest)) {
123
+ if (!SHARED_KEYS.has(key) && key !== "wrapperClassName") {
124
+ inputProps[key] = value;
125
+ }
126
+ }
127
+ return <Input className={inputClassName} {...(inputProps as InputProps)} />;
128
+ }
@@ -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
  }