@atlure/ui 0.7.0 → 0.9.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.7.0",
3
+ "version": "0.9.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.7.0",
41
- "@atlure/tokens": "0.7.0",
42
- "@atlure/types": "0.7.0"
40
+ "@atlure/icons": "0.9.0",
41
+ "@atlure/tokens": "0.9.0",
42
+ "@atlure/types": "0.9.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "nativewind": "^4.2.6",
@@ -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}
@@ -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
+ }