@avenue-ticketing/native 0.1.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/README.md +9 -0
- package/dist/avatar.d.ts +75 -0
- package/dist/avatar.js +300 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +149 -0
- package/dist/badge.js +388 -0
- package/dist/badge.js.map +1 -0
- package/dist/button-group.d.ts +36 -0
- package/dist/button-group.js +186 -0
- package/dist/button-group.js.map +1 -0
- package/dist/button.d.ts +45 -0
- package/dist/button.js +357 -0
- package/dist/button.js.map +1 -0
- package/dist/checkbox.d.ts +31 -0
- package/dist/checkbox.js +212 -0
- package/dist/checkbox.js.map +1 -0
- package/dist/date-picker.d.ts +50 -0
- package/dist/date-picker.js +755 -0
- package/dist/date-picker.js.map +1 -0
- package/dist/dialog.d.ts +62 -0
- package/dist/dialog.js +325 -0
- package/dist/dialog.js.map +1 -0
- package/dist/dropdown.d.ts +85 -0
- package/dist/dropdown.js +977 -0
- package/dist/dropdown.js.map +1 -0
- package/dist/input-group-addon-context.d.ts +10 -0
- package/dist/input-group-addon-context.js +9 -0
- package/dist/input-group-addon-context.js.map +1 -0
- package/dist/input.d.ts +325 -0
- package/dist/input.js +7890 -0
- package/dist/input.js.map +1 -0
- package/dist/radio.d.ts +34 -0
- package/dist/radio.js +177 -0
- package/dist/radio.js.map +1 -0
- package/dist/sheet.d.ts +67 -0
- package/dist/sheet.js +277 -0
- package/dist/sheet.js.map +1 -0
- package/dist/slider.d.ts +22 -0
- package/dist/slider.js +197 -0
- package/dist/slider.js.map +1 -0
- package/dist/tabs.d.ts +69 -0
- package/dist/tabs.js +379 -0
- package/dist/tabs.js.map +1 -0
- package/dist/textarea.d.ts +23 -0
- package/dist/textarea.js +176 -0
- package/dist/textarea.js.map +1 -0
- package/dist/toast.d.ts +32 -0
- package/dist/toast.js +140 -0
- package/dist/toast.js.map +1 -0
- package/dist/toggle.d.ts +31 -0
- package/dist/toggle.js +205 -0
- package/dist/toggle.js.map +1 -0
- package/dist/tooltip.d.ts +44 -0
- package/dist/tooltip.js +293 -0
- package/dist/tooltip.js.map +1 -0
- package/package.json +93 -0
- package/theme-dark.css +362 -0
- package/theme.css +161 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { createContext, useContext, isValidElement, useState, Children, cloneElement } from 'react';
|
|
2
|
+
import { Pressable, View, Text } from 'react-native-css/components';
|
|
3
|
+
import { useNativeVariable } from 'react-native-css';
|
|
4
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
5
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// ../../native/components/base/button-group/button-group.tsx
|
|
8
|
+
var twMerge = extendTailwindMerge({
|
|
9
|
+
extend: {
|
|
10
|
+
theme: {
|
|
11
|
+
text: ["display-xs", "display-sm", "display-md", "display-lg", "display-xl", "display-2xl"]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var cx = twMerge;
|
|
16
|
+
function sortCx(classes) {
|
|
17
|
+
return classes;
|
|
18
|
+
}
|
|
19
|
+
var buttonGroupStyles = sortCx({
|
|
20
|
+
group: "relative z-0 w-max flex-row rounded-lg shadow-xs",
|
|
21
|
+
item: "relative flex-row items-center justify-center overflow-hidden border border-solid border-primary bg-primary",
|
|
22
|
+
itemSelected: "bg-primary_hover",
|
|
23
|
+
itemDisabled: "opacity-50",
|
|
24
|
+
itemPressed: "active:scale-[0.985] active:bg-primary_hover",
|
|
25
|
+
label: "font-semibold text-secondary",
|
|
26
|
+
labelSelected: "text-secondary_hover",
|
|
27
|
+
icon: "text-fg-quaternary",
|
|
28
|
+
hairline: "absolute inset-x-0 bottom-0 h-px bg-[rgba(0,0,0,0.05)]",
|
|
29
|
+
sizes: {
|
|
30
|
+
sm: {
|
|
31
|
+
root: "gap-1.5 px-3.5 py-2",
|
|
32
|
+
label: "text-sm",
|
|
33
|
+
leading: "pl-3",
|
|
34
|
+
iconOnly: "px-2.5",
|
|
35
|
+
icon: 20
|
|
36
|
+
},
|
|
37
|
+
md: {
|
|
38
|
+
root: "gap-1.5 px-4 py-2.5",
|
|
39
|
+
label: "text-sm",
|
|
40
|
+
leading: "pl-3.5",
|
|
41
|
+
iconOnly: "px-3",
|
|
42
|
+
icon: 20
|
|
43
|
+
},
|
|
44
|
+
lg: {
|
|
45
|
+
root: "gap-2 px-4.5 py-2.5",
|
|
46
|
+
label: "text-md",
|
|
47
|
+
leading: "pl-4",
|
|
48
|
+
iconOnly: "px-3.5",
|
|
49
|
+
icon: 20
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
first: "rounded-l-lg",
|
|
53
|
+
last: "rounded-r-lg",
|
|
54
|
+
only: "rounded-lg",
|
|
55
|
+
/** Overlap the shared 1px border, same as web `-space-x-px`. */
|
|
56
|
+
overlap: "-mr-px"
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// ../core/src/is-react-component.ts
|
|
60
|
+
var isFunctionComponent = (component) => {
|
|
61
|
+
return typeof component === "function";
|
|
62
|
+
};
|
|
63
|
+
var isClassComponent = (component) => {
|
|
64
|
+
return typeof component === "function" && component.prototype && (!!component.prototype.isReactComponent || !!component.prototype.render);
|
|
65
|
+
};
|
|
66
|
+
var isForwardRefComponent = (component) => {
|
|
67
|
+
return typeof component === "object" && component !== null && component.$$typeof.toString() === "Symbol(react.forward_ref)";
|
|
68
|
+
};
|
|
69
|
+
var isReactComponent = (component) => {
|
|
70
|
+
return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);
|
|
71
|
+
};
|
|
72
|
+
var ButtonGroupContext = createContext(null);
|
|
73
|
+
function keyList(keys) {
|
|
74
|
+
if (!keys) return [];
|
|
75
|
+
return [...keys].map(String);
|
|
76
|
+
}
|
|
77
|
+
var ButtonGroupItem = ({
|
|
78
|
+
id,
|
|
79
|
+
children,
|
|
80
|
+
iconLeading: IconLeading,
|
|
81
|
+
iconTrailing: IconTrailing,
|
|
82
|
+
isDisabled: isDisabledProp = false,
|
|
83
|
+
className,
|
|
84
|
+
accessibilityLabel,
|
|
85
|
+
segmentPosition = "only"
|
|
86
|
+
}) => {
|
|
87
|
+
const group = useContext(ButtonGroupContext);
|
|
88
|
+
const size = group?.size ?? "md";
|
|
89
|
+
const sizeStyles = buttonGroupStyles.sizes[size];
|
|
90
|
+
const isSelected = group?.isSelected(id) ?? false;
|
|
91
|
+
const isDisabled = Boolean(group?.isDisabled || isDisabledProp);
|
|
92
|
+
const isIcon = Boolean((IconLeading || IconTrailing) && !children);
|
|
93
|
+
const fgQuaternary = useNativeVariable("--color-fg-quaternary") ?? "#a4a7ae";
|
|
94
|
+
const fgQuaternaryHover = useNativeVariable("--color-fg-quaternary_hover") ?? fgQuaternary;
|
|
95
|
+
const iconColor = isSelected ? fgQuaternaryHover : fgQuaternary;
|
|
96
|
+
const LeadingIcon = isReactComponent(IconLeading) ? IconLeading : null;
|
|
97
|
+
const TrailingIcon = isReactComponent(IconTrailing) ? IconTrailing : null;
|
|
98
|
+
const label = typeof children === "string" || typeof children === "number" ? String(children) : null;
|
|
99
|
+
return /* @__PURE__ */ jsxs(
|
|
100
|
+
Pressable,
|
|
101
|
+
{
|
|
102
|
+
accessibilityRole: "button",
|
|
103
|
+
accessibilityLabel: accessibilityLabel ?? label ?? void 0,
|
|
104
|
+
accessibilityState: { selected: isSelected, disabled: isDisabled },
|
|
105
|
+
disabled: isDisabled,
|
|
106
|
+
onPress: () => group?.toggle(id),
|
|
107
|
+
className: cx(
|
|
108
|
+
buttonGroupStyles.item,
|
|
109
|
+
buttonGroupStyles.itemPressed,
|
|
110
|
+
sizeStyles.root,
|
|
111
|
+
isIcon && sizeStyles.iconOnly,
|
|
112
|
+
IconLeading && !isIcon && sizeStyles.leading,
|
|
113
|
+
isSelected && buttonGroupStyles.itemSelected,
|
|
114
|
+
isDisabled && buttonGroupStyles.itemDisabled,
|
|
115
|
+
segmentPosition === "only" && buttonGroupStyles.only,
|
|
116
|
+
segmentPosition === "first" && buttonGroupStyles.first,
|
|
117
|
+
segmentPosition === "last" && buttonGroupStyles.last,
|
|
118
|
+
segmentPosition !== "last" && segmentPosition !== "only" && buttonGroupStyles.overlap,
|
|
119
|
+
className
|
|
120
|
+
),
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ jsx(View, { pointerEvents: "none", className: buttonGroupStyles.hairline }),
|
|
123
|
+
LeadingIcon && /* @__PURE__ */ jsx(LeadingIcon, { className: buttonGroupStyles.icon, size: sizeStyles.icon, color: iconColor }),
|
|
124
|
+
isValidElement(IconLeading) && IconLeading,
|
|
125
|
+
label ? /* @__PURE__ */ jsx(
|
|
126
|
+
Text,
|
|
127
|
+
{
|
|
128
|
+
className: cx(
|
|
129
|
+
buttonGroupStyles.label,
|
|
130
|
+
sizeStyles.label,
|
|
131
|
+
isSelected && buttonGroupStyles.labelSelected
|
|
132
|
+
),
|
|
133
|
+
children: label
|
|
134
|
+
}
|
|
135
|
+
) : children,
|
|
136
|
+
TrailingIcon && /* @__PURE__ */ jsx(TrailingIcon, { className: buttonGroupStyles.icon, size: sizeStyles.icon, color: iconColor }),
|
|
137
|
+
isValidElement(IconTrailing) && IconTrailing
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
ButtonGroupItem.displayName = "ButtonGroupItem";
|
|
143
|
+
var ButtonGroup = ({
|
|
144
|
+
children,
|
|
145
|
+
size = "md",
|
|
146
|
+
className,
|
|
147
|
+
isDisabled = false,
|
|
148
|
+
selectionMode = "single",
|
|
149
|
+
selectedKeys,
|
|
150
|
+
defaultSelectedKeys,
|
|
151
|
+
onSelectionChange
|
|
152
|
+
}) => {
|
|
153
|
+
const [uncontrolled, setUncontrolled] = useState(() => keyList(defaultSelectedKeys));
|
|
154
|
+
const isControlled = selectedKeys !== void 0;
|
|
155
|
+
const keys = isControlled ? keyList(selectedKeys) : uncontrolled;
|
|
156
|
+
const toggle = (id) => {
|
|
157
|
+
if (isDisabled) return;
|
|
158
|
+
const selected = new Set(keys);
|
|
159
|
+
const next = selectionMode === "multiple" ? selected.has(id) ? keys.filter((key) => key !== id) : [...keys, id] : selected.has(id) ? [] : [id];
|
|
160
|
+
if (!isControlled) setUncontrolled(next);
|
|
161
|
+
onSelectionChange?.(next);
|
|
162
|
+
};
|
|
163
|
+
const items = Children.toArray(children);
|
|
164
|
+
const segments = items.map((child, index) => {
|
|
165
|
+
if (!isValidElement(child)) return child;
|
|
166
|
+
const position = items.length === 1 ? "only" : index === 0 ? "first" : index === items.length - 1 ? "last" : "middle";
|
|
167
|
+
return cloneElement(child, { segmentPosition: position });
|
|
168
|
+
});
|
|
169
|
+
return /* @__PURE__ */ jsx(
|
|
170
|
+
ButtonGroupContext.Provider,
|
|
171
|
+
{
|
|
172
|
+
value: {
|
|
173
|
+
size,
|
|
174
|
+
isDisabled,
|
|
175
|
+
isSelected: (id) => keys.includes(id),
|
|
176
|
+
toggle
|
|
177
|
+
},
|
|
178
|
+
children: /* @__PURE__ */ jsx(View, { className: cx(buttonGroupStyles.group, className), children: segments })
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
ButtonGroup.displayName = "ButtonGroup";
|
|
183
|
+
|
|
184
|
+
export { ButtonGroup, ButtonGroupItem };
|
|
185
|
+
//# sourceMappingURL=button-group.js.map
|
|
186
|
+
//# sourceMappingURL=button-group.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../core/src/cx.ts","../../core/src/button-group.ts","../../core/src/is-react-component.ts","../../../native/components/base/button-group/button-group.tsx"],"names":[],"mappings":";;;;;;;AAEA,IAAM,UAAU,mBAAA,CAAoB;AAAA,EAChC,MAAA,EAAQ;AAAA,IACJ,KAAA,EAAO;AAAA,MACH,MAAM,CAAC,YAAA,EAAc,cAAc,YAAA,EAAc,YAAA,EAAc,cAAc,aAAa;AAAA;AAC9F;AAER,CAAC,CAAA;AAGM,IAAM,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AO,YAAA,CAAa,KAAA,EAA6C,EAAE,eAAA,EAAiB,UAAU,CAAA;AAAA,EAClG,CAAC,CAAA;AAED,EAAA,uBACI,GAAA;AAAA,IAAC,kBAAA,CAAmB,QAAA;AAAA,IAAnB;AAAA,MACG,KAAA,EAAO;AAAA,QACH,IAAA;AAAA,QACA,UAAA;AAAA,QACA,UAAA,EAAY,CAAC,EAAA,KAAO,IAAA,CAAK,SAAS,EAAE,CAAA;AAAA,QACpC;AAAA,OACJ;AAAA,MAEA,QAAA,kBAAA,GAAA,CAAC,QAAK,SAAA,EAAW,EAAA,CAAG,kBAAkB,KAAA,EAAO,SAAS,GAAI,QAAA,EAAA,QAAA,EAAS;AAAA;AAAA,GACvE;AAER;AAEA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"button-group.js","sourcesContent":["import { extendTailwindMerge } from \"tailwind-merge\";\n\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: {\n text: [\"display-xs\", \"display-sm\", \"display-md\", \"display-lg\", \"display-xl\", \"display-2xl\"],\n },\n },\n});\n\n/** Merge Tailwind / NativeWind class strings. */\nexport const cx = twMerge;\n\n/** Identity helper so Tailwind IntelliSense can sort style maps. */\nexport function sortCx<T extends Record<string, string | number | Record<string, string | number | Record<string, string | number>>>>(classes: T): T {\n return classes;\n}\n","import { sortCx } from \"./cx\";\n\n//////////////////////////////////////////////// TYPES\n\nexport const BUTTON_GROUP_SIZES = [\"sm\", \"md\", \"lg\"] as const;\nexport type ButtonGroupSize = (typeof BUTTON_GROUP_SIZES)[number];\n\n//////////////////////////////////////////////// WEB STYLES\n// Exact class strings from `components/base/button-group`. Figma: Button groups (16:399).\n\n/** Spread focus ring — 2px surface gap + 4px focus-ring (matches Button secondary). */\nconst buttonGroupWebFocusShadow =\n \"focus-visible:outline-none focus-visible:[box-shadow:var(--shadow-xs-skeuomorphic),0px_0px_0px_2px_var(--color-bg-primary),0px_0px_0px_4px_var(--color-focus-ring)]\";\n\nexport const buttonGroupWebStyles = sortCx({\n common: {\n root: [\n \"group/button-group relative inline-flex h-max cursor-pointer items-center overflow-hidden bg-primary font-semibold whitespace-nowrap text-secondary shadow-skeuomorphic ring-1 ring-primary transition duration-100 ease-linear ring-inset\",\n \"pressed:scale-[0.985] pressed:duration-100 pressed:ease-linear motion-reduce:pressed:scale-100\",\n \"after:pointer-events-none after:absolute after:inset-0 after:content-[''] after:[box-shadow:inset_0px_-1px_0px_0px_rgba(0,0,0,0.05)]\",\n \"hover:bg-primary_hover hover:text-secondary_hover focus-visible:z-10\",\n buttonGroupWebFocusShadow,\n \"disabled:cursor-not-allowed disabled:opacity-50\",\n \"selected:bg-primary_hover selected:text-secondary_hover\",\n ].join(\" \"),\n icon: \"pointer-events-none text-fg-quaternary transition-[inherit] group-hover/button-group:text-fg-quaternary_hover group-selected/button-group:text-fg-quaternary_hover\",\n },\n sizes: {\n sm: {\n root: \"gap-1.5 px-3.5 py-2 text-sm not-last:pr-[calc(calc(var(--spacing)*3.5)+1px)] first:rounded-l-lg last:rounded-r-lg data-icon-leading:pl-3 data-icon-only:px-2.5\",\n icon: \"size-5\",\n },\n md: {\n root: \"gap-1.5 px-4 py-2.5 text-sm not-last:pr-[calc(calc(var(--spacing)*4)+1px)] first:rounded-l-lg last:rounded-r-lg data-icon-leading:pl-3.5 data-icon-only:px-3\",\n icon: \"size-5\",\n },\n lg: {\n root: \"gap-2 px-4.5 py-2.5 text-md not-last:pr-[calc(calc(var(--spacing)*4.5)+1px)] first:rounded-l-lg last:rounded-r-lg data-icon-leading:pl-4 data-icon-only:px-3.5\",\n icon: \"size-5\",\n },\n },\n group: \"relative z-0 inline-flex w-max -space-x-px rounded-lg shadow-xs\",\n});\n\n//////////////////////////////////////////////// NATIVE STYLES\n// Same sizes and segmented corners. Skips CSS-only selectors (first/last, hover, focus ring, ::after).\n\nexport const buttonGroupStyles = sortCx({\n group: \"relative z-0 w-max flex-row rounded-lg shadow-xs\",\n item: \"relative flex-row items-center justify-center overflow-hidden border border-solid border-primary bg-primary\",\n itemSelected: \"bg-primary_hover\",\n itemDisabled: \"opacity-50\",\n itemPressed: \"active:scale-[0.985] active:bg-primary_hover\",\n label: \"font-semibold text-secondary\",\n labelSelected: \"text-secondary_hover\",\n icon: \"text-fg-quaternary\",\n hairline: \"absolute inset-x-0 bottom-0 h-px bg-[rgba(0,0,0,0.05)]\",\n sizes: {\n sm: {\n root: \"gap-1.5 px-3.5 py-2\",\n label: \"text-sm\",\n leading: \"pl-3\",\n iconOnly: \"px-2.5\",\n icon: 20,\n },\n md: {\n root: \"gap-1.5 px-4 py-2.5\",\n label: \"text-sm\",\n leading: \"pl-3.5\",\n iconOnly: \"px-3\",\n icon: 20,\n },\n lg: {\n root: \"gap-2 px-4.5 py-2.5\",\n label: \"text-md\",\n leading: \"pl-4\",\n iconOnly: \"px-3.5\",\n icon: 20,\n },\n },\n first: \"rounded-l-lg\",\n last: \"rounded-r-lg\",\n only: \"rounded-lg\",\n /** Overlap the shared 1px border, same as web `-space-x-px`. */\n overlap: \"-mr-px\",\n});\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type React from \"react\";\n\ntype ReactComponent = React.FC<any> | React.ComponentClass<any, any>;\n\nexport const isFunctionComponent = (component: any): component is React.FC<any> => {\n return typeof component === \"function\";\n};\n\nexport const isClassComponent = (component: any): component is React.ComponentClass<any, any> => {\n return typeof component === \"function\" && component.prototype && (!!component.prototype.isReactComponent || !!component.prototype.render);\n};\n\nexport const isForwardRefComponent = (component: any): component is React.ForwardRefExoticComponent<any> => {\n return typeof component === \"object\" && component !== null && component.$$typeof.toString() === \"Symbol(react.forward_ref)\";\n};\n\nexport const isReactComponent = (component: any): component is ReactComponent => {\n return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);\n};\n","import {\n Children,\n cloneElement,\n createContext,\n isValidElement,\n useContext,\n useState,\n type FC,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { Pressable, Text, View } from \"react-native-css/components\";\nimport { useNativeVariable } from \"react-native-css\";\nimport { buttonGroupStyles, type ButtonGroupSize } from \"@avenue-ticketing/core/button-group\";\nimport { cx } from \"@avenue-ticketing/core/cx\";\nimport { isReactComponent } from \"@avenue-ticketing/core/is-react-component\";\n\nexport type { ButtonGroupSize };\n\n//////////////////////////////////////////////// TYPES\n\nexport type ButtonGroupIconProps = {\n className?: string;\n size?: number;\n color?: string;\n};\n\ntype SegmentPosition = \"only\" | \"first\" | \"middle\" | \"last\";\n\nexport interface ButtonGroupItemProps {\n id: string;\n children?: ReactNode;\n iconLeading?: FC<ButtonGroupIconProps> | ReactNode;\n iconTrailing?: FC<ButtonGroupIconProps> | ReactNode;\n isDisabled?: boolean;\n className?: string;\n accessibilityLabel?: string;\n /** Set by `ButtonGroup` so corners and the shared border line up. */\n segmentPosition?: SegmentPosition;\n}\n\nexport interface ButtonGroupProps {\n children: ReactNode;\n size?: ButtonGroupSize;\n className?: string;\n isDisabled?: boolean;\n selectionMode?: \"single\" | \"multiple\";\n selectedKeys?: Iterable<string>;\n defaultSelectedKeys?: Iterable<string>;\n onSelectionChange?: (keys: string[]) => void;\n}\n\ntype ButtonGroupContextValue = {\n size: ButtonGroupSize;\n isDisabled: boolean;\n isSelected: (id: string) => boolean;\n toggle: (id: string) => void;\n};\n\n//////////////////////////////////////////////// CONTEXT\n\nconst ButtonGroupContext = createContext<ButtonGroupContextValue | null>(null);\n\nfunction keyList(keys: Iterable<string> | undefined): string[] {\n if (!keys) return [];\n return [...keys].map(String);\n}\n\n//////////////////////////////////////////////// MAIN\n\nexport const ButtonGroupItem: FC<ButtonGroupItemProps> = ({\n id,\n children,\n iconLeading: IconLeading,\n iconTrailing: IconTrailing,\n isDisabled: isDisabledProp = false,\n className,\n accessibilityLabel,\n segmentPosition = \"only\",\n}) => {\n const group = useContext(ButtonGroupContext);\n const size = group?.size ?? \"md\";\n const sizeStyles = buttonGroupStyles.sizes[size];\n const isSelected = group?.isSelected(id) ?? false;\n const isDisabled = Boolean(group?.isDisabled || isDisabledProp);\n const isIcon = Boolean((IconLeading || IconTrailing) && !children);\n const fgQuaternary = useNativeVariable(\"--color-fg-quaternary\") ?? \"#a4a7ae\";\n const fgQuaternaryHover = useNativeVariable(\"--color-fg-quaternary_hover\") ?? fgQuaternary;\n const iconColor = isSelected ? fgQuaternaryHover : fgQuaternary;\n\n const LeadingIcon = isReactComponent(IconLeading) ? IconLeading : null;\n const TrailingIcon = isReactComponent(IconTrailing) ? IconTrailing : null;\n const label = typeof children === \"string\" || typeof children === \"number\" ? String(children) : null;\n\n return (\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={accessibilityLabel ?? label ?? undefined}\n accessibilityState={{ selected: isSelected, disabled: isDisabled }}\n disabled={isDisabled}\n onPress={() => group?.toggle(id)}\n className={cx(\n buttonGroupStyles.item,\n buttonGroupStyles.itemPressed,\n sizeStyles.root,\n isIcon && sizeStyles.iconOnly,\n IconLeading && !isIcon && sizeStyles.leading,\n isSelected && buttonGroupStyles.itemSelected,\n isDisabled && buttonGroupStyles.itemDisabled,\n segmentPosition === \"only\" && buttonGroupStyles.only,\n segmentPosition === \"first\" && buttonGroupStyles.first,\n segmentPosition === \"last\" && buttonGroupStyles.last,\n segmentPosition !== \"last\" && segmentPosition !== \"only\" && buttonGroupStyles.overlap,\n className,\n )}\n >\n <View pointerEvents=\"none\" className={buttonGroupStyles.hairline} />\n {LeadingIcon && <LeadingIcon className={buttonGroupStyles.icon} size={sizeStyles.icon} color={iconColor} />}\n {isValidElement(IconLeading) && IconLeading}\n {label ? (\n <Text\n className={cx(\n buttonGroupStyles.label,\n sizeStyles.label,\n isSelected && buttonGroupStyles.labelSelected,\n )}\n >\n {label}\n </Text>\n ) : (\n children\n )}\n {TrailingIcon && <TrailingIcon className={buttonGroupStyles.icon} size={sizeStyles.icon} color={iconColor} />}\n {isValidElement(IconTrailing) && IconTrailing}\n </Pressable>\n );\n};\n\nButtonGroupItem.displayName = \"ButtonGroupItem\";\n\nexport const ButtonGroup: FC<ButtonGroupProps> = ({\n children,\n size = \"md\",\n className,\n isDisabled = false,\n selectionMode = \"single\",\n selectedKeys,\n defaultSelectedKeys,\n onSelectionChange,\n}) => {\n const [uncontrolled, setUncontrolled] = useState(() => keyList(defaultSelectedKeys));\n const isControlled = selectedKeys !== undefined;\n const keys = isControlled ? keyList(selectedKeys) : uncontrolled;\n\n const toggle = (id: string) => {\n if (isDisabled) return;\n const selected = new Set(keys);\n const next =\n selectionMode === \"multiple\"\n ? selected.has(id)\n ? keys.filter((key) => key !== id)\n : [...keys, id]\n : selected.has(id)\n ? []\n : [id];\n if (!isControlled) setUncontrolled(next);\n onSelectionChange?.(next);\n };\n\n const items = Children.toArray(children);\n const segments = items.map((child, index) => {\n if (!isValidElement(child)) return child;\n const position: SegmentPosition =\n items.length === 1 ? \"only\" : index === 0 ? \"first\" : index === items.length - 1 ? \"last\" : \"middle\";\n return cloneElement(child as ReactElement<ButtonGroupItemProps>, { segmentPosition: position });\n });\n\n return (\n <ButtonGroupContext.Provider\n value={{\n size,\n isDisabled,\n isSelected: (id) => keys.includes(id),\n toggle,\n }}\n >\n <View className={cx(buttonGroupStyles.group, className)}>{segments}</View>\n </ButtonGroupContext.Provider>\n );\n};\n\nButtonGroup.displayName = \"ButtonGroup\";\n"]}
|
package/dist/button.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
import { PressableProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
declare const BUTTON_SIZES: readonly ["xs", "sm", "md", "lg", "xl"];
|
|
5
|
+
type ButtonSize = (typeof BUTTON_SIZES)[number];
|
|
6
|
+
declare const BUTTON_COLORS: readonly ["primary", "brand", "secondary", "tertiary", "link-color", "link-gray", "primary-destructive", "secondary-destructive", "tertiary-destructive", "link-destructive"];
|
|
7
|
+
type ButtonColor = (typeof BUTTON_COLORS)[number];
|
|
8
|
+
|
|
9
|
+
/** Props passed to `iconLeading` / `iconTrailing` (web `data-icon` + RN size). */
|
|
10
|
+
type ButtonIconProps = {
|
|
11
|
+
className?: string;
|
|
12
|
+
/** Pixel size — web uses `*:data-icon:size-*`. */
|
|
13
|
+
size?: number;
|
|
14
|
+
};
|
|
15
|
+
interface ButtonProps extends Omit<PressableProps, "children" | "disabled" | "style"> {
|
|
16
|
+
isDisabled?: boolean;
|
|
17
|
+
isLoading?: boolean;
|
|
18
|
+
size?: ButtonSize;
|
|
19
|
+
color?: ButtonColor;
|
|
20
|
+
iconLeading?: FC<ButtonIconProps> | ReactNode;
|
|
21
|
+
iconTrailing?: FC<ButtonIconProps> | ReactNode;
|
|
22
|
+
noTextPadding?: boolean;
|
|
23
|
+
showTextWhileLoading?: boolean;
|
|
24
|
+
/** Opens via `Linking` (native analogue of web `href`). */
|
|
25
|
+
href?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Button copy (RN `Button`’s `title`). Always rendered inside `<Text>`.
|
|
28
|
+
*/
|
|
29
|
+
title?: string;
|
|
30
|
+
/** Custom content. Prefer `title` for plain strings. */
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
className?: string;
|
|
33
|
+
/** Flatten into InputGroup trailing/leading slot (web `in-data-input-wrapper`). */
|
|
34
|
+
inInputGroup?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* NativeWind button — shared Tailwind class maps from `@avenue-ticketing/core/button`.
|
|
38
|
+
*
|
|
39
|
+
* NativeWind v5 only rewrites `react-native` imports in the *app*. A published
|
|
40
|
+
* package must import `Pressable`/`Text` from `react-native-css/components` or
|
|
41
|
+
* `className` is a no-op (empty labels, missing chrome).
|
|
42
|
+
*/
|
|
43
|
+
declare const Button: FC<ButtonProps>;
|
|
44
|
+
|
|
45
|
+
export { Button, type ButtonColor, type ButtonIconProps, type ButtonProps, type ButtonSize };
|
package/dist/button.js
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { isValidElement, useEffect } from 'react';
|
|
2
|
+
import { Linking } from 'react-native';
|
|
3
|
+
import { Pressable, View, Text } from 'react-native-css/components';
|
|
4
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
5
|
+
import { useInputGroupAddon } from '@avenue-ticketing/native/input-group-addon-context';
|
|
6
|
+
import Animated, { useSharedValue, withRepeat, withTiming, Easing, useAnimatedStyle } from 'react-native-reanimated';
|
|
7
|
+
import Svg, { Path } from 'react-native-svg';
|
|
8
|
+
import { styled } from 'nativewind';
|
|
9
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
// ../../native/components/base/buttons/button.tsx
|
|
12
|
+
var twMerge = extendTailwindMerge({
|
|
13
|
+
extend: {
|
|
14
|
+
theme: {
|
|
15
|
+
text: ["display-xs", "display-sm", "display-md", "display-lg", "display-xl", "display-2xl"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var cx = twMerge;
|
|
20
|
+
function sortCx(classes) {
|
|
21
|
+
return classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ../core/src/button.ts
|
|
25
|
+
function isLinkButtonColor(color) {
|
|
26
|
+
return color === "link-gray" || color === "link-color" || color === "link-destructive";
|
|
27
|
+
}
|
|
28
|
+
function isSolidSkeuomorphic(color) {
|
|
29
|
+
return color === "primary" || color === "brand" || color === "primary-destructive";
|
|
30
|
+
}
|
|
31
|
+
function isSecondarySkeuomorphic(color) {
|
|
32
|
+
return color === "secondary" || color === "secondary-destructive";
|
|
33
|
+
}
|
|
34
|
+
var BUTTON_ICON_SIZE_PX = {
|
|
35
|
+
xs: 16,
|
|
36
|
+
sm: 20,
|
|
37
|
+
md: 20,
|
|
38
|
+
lg: 20,
|
|
39
|
+
xl: 20
|
|
40
|
+
};
|
|
41
|
+
function resolveButtonIconSizePx(size, isIconOnly = false) {
|
|
42
|
+
if (size === "xl" && isIconOnly) return 24;
|
|
43
|
+
return BUTTON_ICON_SIZE_PX[size];
|
|
44
|
+
}
|
|
45
|
+
function resolveButtonIconSizeClass(size, isIconOnly = false) {
|
|
46
|
+
if (size === "xl" && isIconOnly) return "size-6";
|
|
47
|
+
if (size === "xs") return "size-4";
|
|
48
|
+
return "size-5";
|
|
49
|
+
}
|
|
50
|
+
var BUTTON_LOADING_SPINNER_PATH = "M232,128a104,104,0,0,1-208,0c0-41,23.81-78.36,60.66-95.27a8,8,0,0,1,6.68,14.54C60,61.46,40,93.27,40,128a88,88,0,0,0,176,0c0-34.73-20-66.54-51.34-80.73a8,8,0,0,1,6.68-14.54C208.19,49.64,232,87,232,128Z";
|
|
51
|
+
var buttonStyles = sortCx({
|
|
52
|
+
common: {
|
|
53
|
+
// Avoid bare `flex` — NativeWind maps it like web (row) and can break parents.
|
|
54
|
+
root: "relative flex-row items-center justify-center overflow-visible rounded-full shrink-0",
|
|
55
|
+
icon: "shrink-0",
|
|
56
|
+
label: "shrink-0 font-semibold"
|
|
57
|
+
},
|
|
58
|
+
sizes: {
|
|
59
|
+
// Padding / height / gap match `buttonWebStyles.sizes` (web root).
|
|
60
|
+
xs: {
|
|
61
|
+
root: "h-8 min-h-8 gap-1 px-[0.625rem] py-1.5",
|
|
62
|
+
label: "text-sm",
|
|
63
|
+
iconOnly: "size-8 min-h-8 min-w-8 p-2"
|
|
64
|
+
},
|
|
65
|
+
sm: {
|
|
66
|
+
root: "h-9 min-h-9 gap-1 px-3 py-2",
|
|
67
|
+
label: "text-sm",
|
|
68
|
+
iconOnly: "size-9 min-h-9 min-w-9 p-2"
|
|
69
|
+
},
|
|
70
|
+
md: {
|
|
71
|
+
root: "h-10 min-h-10 gap-1 px-3.5 py-2.5",
|
|
72
|
+
label: "text-sm",
|
|
73
|
+
iconOnly: "size-10 min-h-10 min-w-10 p-2.5"
|
|
74
|
+
},
|
|
75
|
+
lg: {
|
|
76
|
+
root: "h-11 min-h-11 gap-1.5 px-4 py-2.5",
|
|
77
|
+
label: "text-md",
|
|
78
|
+
iconOnly: "size-11 min-h-11 min-w-11 p-3"
|
|
79
|
+
},
|
|
80
|
+
xl: {
|
|
81
|
+
root: "h-12 min-h-12 gap-1.5 px-[1.125rem] py-3",
|
|
82
|
+
label: "text-md",
|
|
83
|
+
iconOnly: "size-12 min-h-12 min-w-12 p-3"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
/** Web `disabled:opacity-30` (primary) / `disabled:opacity-50` (others). */
|
|
87
|
+
disabledOpacity: {
|
|
88
|
+
primary: "opacity-30",
|
|
89
|
+
brand: "opacity-50",
|
|
90
|
+
secondary: "opacity-50",
|
|
91
|
+
tertiary: "opacity-50",
|
|
92
|
+
"link-color": "opacity-50",
|
|
93
|
+
"link-gray": "opacity-50",
|
|
94
|
+
"primary-destructive": "opacity-50",
|
|
95
|
+
"secondary-destructive": "opacity-50",
|
|
96
|
+
"tertiary-destructive": "opacity-50",
|
|
97
|
+
"link-destructive": "opacity-50"
|
|
98
|
+
},
|
|
99
|
+
/** Native InputGroup addon — shell owns border/height; button is a flush inner segment. */
|
|
100
|
+
inputGroup: {
|
|
101
|
+
root: "h-auto min-h-0 self-stretch rounded-none border-0 bg-primary shadow-none overflow-hidden",
|
|
102
|
+
sm: "gap-1 px-3 py-2",
|
|
103
|
+
md: "gap-1 px-3.5 py-2.5",
|
|
104
|
+
lg: "gap-1.5 px-4 py-2.5",
|
|
105
|
+
xs: "gap-1 px-3 py-2",
|
|
106
|
+
xl: "gap-1.5 px-4 py-2.5"
|
|
107
|
+
},
|
|
108
|
+
colors: {
|
|
109
|
+
primary: {
|
|
110
|
+
root: "bg-primary-solid",
|
|
111
|
+
label: "text-white",
|
|
112
|
+
/** Web `*:data-icon:not([data-icon=loading]):text-white/70` */
|
|
113
|
+
icon: "text-white/70",
|
|
114
|
+
/** Loading icon inherits root `text-white`. */
|
|
115
|
+
spinner: "text-white"
|
|
116
|
+
},
|
|
117
|
+
brand: {
|
|
118
|
+
root: "bg-brand-solid",
|
|
119
|
+
label: "text-primary_on-brand",
|
|
120
|
+
icon: "text-primary_on-brand",
|
|
121
|
+
spinner: "text-primary_on-brand"
|
|
122
|
+
},
|
|
123
|
+
secondary: {
|
|
124
|
+
root: "border border-solid border-primary bg-primary",
|
|
125
|
+
label: "text-secondary",
|
|
126
|
+
icon: "text-fg-secondary",
|
|
127
|
+
spinner: "text-fg-secondary"
|
|
128
|
+
},
|
|
129
|
+
tertiary: {
|
|
130
|
+
root: "border border-transparent bg-transparent",
|
|
131
|
+
label: "text-tertiary",
|
|
132
|
+
icon: "text-fg-tertiary",
|
|
133
|
+
spinner: "text-fg-tertiary"
|
|
134
|
+
},
|
|
135
|
+
"link-color": {
|
|
136
|
+
// Web: underline decoration transparent until hover — native uses press underline.
|
|
137
|
+
root: "h-auto min-h-0 bg-transparent px-0 py-0",
|
|
138
|
+
label: "text-brand-secondary",
|
|
139
|
+
icon: "text-brand-secondary",
|
|
140
|
+
spinner: "text-brand-secondary"
|
|
141
|
+
},
|
|
142
|
+
"link-gray": {
|
|
143
|
+
root: "h-auto min-h-0 bg-transparent px-0 py-0",
|
|
144
|
+
label: "text-tertiary",
|
|
145
|
+
icon: "text-fg-tertiary",
|
|
146
|
+
spinner: "text-fg-tertiary"
|
|
147
|
+
},
|
|
148
|
+
"primary-destructive": {
|
|
149
|
+
root: "bg-error-solid",
|
|
150
|
+
label: "text-white",
|
|
151
|
+
icon: "text-white/70",
|
|
152
|
+
spinner: "text-white"
|
|
153
|
+
},
|
|
154
|
+
"secondary-destructive": {
|
|
155
|
+
root: "border border-solid border-primary bg-primary",
|
|
156
|
+
label: "text-error-primary",
|
|
157
|
+
icon: "text-fg-error-secondary",
|
|
158
|
+
spinner: "text-fg-error-secondary"
|
|
159
|
+
},
|
|
160
|
+
"tertiary-destructive": {
|
|
161
|
+
root: "border border-transparent bg-transparent",
|
|
162
|
+
label: "text-error-primary",
|
|
163
|
+
icon: "text-fg-error-secondary",
|
|
164
|
+
spinner: "text-fg-error-secondary"
|
|
165
|
+
},
|
|
166
|
+
"link-destructive": {
|
|
167
|
+
root: "h-auto min-h-0 bg-transparent px-0 py-0",
|
|
168
|
+
label: "text-error-primary",
|
|
169
|
+
icon: "text-error-primary",
|
|
170
|
+
spinner: "text-error-primary"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// ../core/src/is-react-component.ts
|
|
176
|
+
var isFunctionComponent = (component) => {
|
|
177
|
+
return typeof component === "function";
|
|
178
|
+
};
|
|
179
|
+
var isClassComponent = (component) => {
|
|
180
|
+
return typeof component === "function" && component.prototype && (!!component.prototype.isReactComponent || !!component.prototype.render);
|
|
181
|
+
};
|
|
182
|
+
var isForwardRefComponent = (component) => {
|
|
183
|
+
return typeof component === "object" && component !== null && component.$$typeof.toString() === "Symbol(react.forward_ref)";
|
|
184
|
+
};
|
|
185
|
+
var isReactComponent = (component) => {
|
|
186
|
+
return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// ../../native/components/base/buttons/button.styles.ts
|
|
190
|
+
var nativeButtonInteraction = sortCx({
|
|
191
|
+
root: "active:scale-[0.985]",
|
|
192
|
+
drop: "shadow-xs",
|
|
193
|
+
clip: "absolute inset-0 overflow-hidden rounded-full",
|
|
194
|
+
insetRing: "absolute inset-0 rounded-full border border-solid border-[rgba(0,0,0,0.18)]",
|
|
195
|
+
bottomWeight: "absolute inset-x-0 bottom-0 h-0.5 bg-[rgba(0,0,0,0.05)]",
|
|
196
|
+
topHighlight: "absolute left-px right-px top-px h-px bg-[rgba(255,255,255,0.12)]",
|
|
197
|
+
secondaryBottom: "absolute inset-x-0 bottom-0 h-px bg-[rgba(0,0,0,0.05)]",
|
|
198
|
+
colors: {
|
|
199
|
+
primary: "active:bg-fg-tertiary_hover",
|
|
200
|
+
brand: "active:bg-brand-solid_hover",
|
|
201
|
+
secondary: "active:bg-primary_hover",
|
|
202
|
+
tertiary: "active:bg-primary_hover",
|
|
203
|
+
// Web link hover: underline + color shift. RN uses press = hover.
|
|
204
|
+
"link-color": "active:opacity-80",
|
|
205
|
+
"link-gray": "active:opacity-80",
|
|
206
|
+
"primary-destructive": "active:bg-error-solid_hover",
|
|
207
|
+
"secondary-destructive": "active:bg-error-primary",
|
|
208
|
+
"tertiary-destructive": "active:bg-error-primary",
|
|
209
|
+
"link-destructive": "active:opacity-80"
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
function hasPressScale(color) {
|
|
213
|
+
return !isLinkButtonColor(color);
|
|
214
|
+
}
|
|
215
|
+
var StyledSvg = styled(Svg);
|
|
216
|
+
var ButtonSpinner = ({ className, size, showTextWhileLoading }) => {
|
|
217
|
+
const rotation = useSharedValue(0);
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
rotation.value = withRepeat(
|
|
220
|
+
withTiming(360, { duration: 1e3, easing: Easing.linear }),
|
|
221
|
+
-1,
|
|
222
|
+
false
|
|
223
|
+
);
|
|
224
|
+
}, [rotation]);
|
|
225
|
+
const spinStyle = useAnimatedStyle(() => ({
|
|
226
|
+
transform: [{ rotate: `${rotation.value}deg` }]
|
|
227
|
+
}));
|
|
228
|
+
return /* @__PURE__ */ jsx(
|
|
229
|
+
View,
|
|
230
|
+
{
|
|
231
|
+
pointerEvents: "none",
|
|
232
|
+
className: cx(
|
|
233
|
+
!showTextWhileLoading && "absolute inset-0 items-center justify-center"
|
|
234
|
+
),
|
|
235
|
+
children: /* @__PURE__ */ jsx(Animated.View, { style: spinStyle, children: /* @__PURE__ */ jsx(
|
|
236
|
+
StyledSvg,
|
|
237
|
+
{
|
|
238
|
+
width: size,
|
|
239
|
+
height: size,
|
|
240
|
+
viewBox: "0 0 256 256",
|
|
241
|
+
accessibilityElementsHidden: true,
|
|
242
|
+
className,
|
|
243
|
+
children: /* @__PURE__ */ jsx(Path, { fill: "currentColor", d: BUTTON_LOADING_SPINNER_PATH })
|
|
244
|
+
}
|
|
245
|
+
) })
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
var Button = ({
|
|
250
|
+
size = "md",
|
|
251
|
+
color = "primary",
|
|
252
|
+
title,
|
|
253
|
+
children,
|
|
254
|
+
className,
|
|
255
|
+
noTextPadding,
|
|
256
|
+
iconLeading: IconLeading,
|
|
257
|
+
iconTrailing: IconTrailing,
|
|
258
|
+
isDisabled: disabled = false,
|
|
259
|
+
isLoading: loading = false,
|
|
260
|
+
showTextWhileLoading,
|
|
261
|
+
href,
|
|
262
|
+
onPress,
|
|
263
|
+
inInputGroup = false,
|
|
264
|
+
...props
|
|
265
|
+
}) => {
|
|
266
|
+
const inAddon = useInputGroupAddon();
|
|
267
|
+
const flattenInGroup = inInputGroup || inAddon;
|
|
268
|
+
const titleFromChildren = typeof children === "string" || typeof children === "number" ? String(children) : null;
|
|
269
|
+
const titleText = title ?? titleFromChildren;
|
|
270
|
+
const customChildren = titleText == null ? children : null;
|
|
271
|
+
const isIcon = Boolean((IconLeading || IconTrailing) && !titleText && !customChildren);
|
|
272
|
+
const isLinkType = isLinkButtonColor(color);
|
|
273
|
+
const padText = !(isLinkType || noTextPadding);
|
|
274
|
+
const isInactive = disabled || loading;
|
|
275
|
+
const showTitle = Boolean(titleText) && (!loading || showTextWhileLoading);
|
|
276
|
+
const iconSizePx = resolveButtonIconSizePx(size, isIcon);
|
|
277
|
+
const iconClassName = cx(
|
|
278
|
+
buttonStyles.common.icon,
|
|
279
|
+
resolveButtonIconSizeClass(size, isIcon),
|
|
280
|
+
buttonStyles.colors[color].icon
|
|
281
|
+
);
|
|
282
|
+
const LeadingIcon = isReactComponent(IconLeading) ? IconLeading : null;
|
|
283
|
+
const TrailingIcon = isReactComponent(IconTrailing) ? IconTrailing : null;
|
|
284
|
+
const handlePress = (event) => {
|
|
285
|
+
if (isInactive) return;
|
|
286
|
+
if (href) {
|
|
287
|
+
void Linking.openURL(href);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
onPress?.(event);
|
|
291
|
+
};
|
|
292
|
+
return /* @__PURE__ */ jsx(
|
|
293
|
+
Pressable,
|
|
294
|
+
{
|
|
295
|
+
accessibilityRole: "button",
|
|
296
|
+
accessibilityLabel: titleText ?? void 0,
|
|
297
|
+
accessibilityState: { disabled: isInactive, busy: loading },
|
|
298
|
+
disabled: isInactive,
|
|
299
|
+
onPress: handlePress,
|
|
300
|
+
className: cx(
|
|
301
|
+
buttonStyles.common.root,
|
|
302
|
+
flattenInGroup ? cx(buttonStyles.inputGroup.root, buttonStyles.inputGroup[size]) : cx(buttonStyles.sizes[size].root, isIcon && buttonStyles.sizes[size].iconOnly),
|
|
303
|
+
flattenInGroup ? "bg-primary" : buttonStyles.colors[color].root,
|
|
304
|
+
!flattenInGroup && hasPressScale(color) && nativeButtonInteraction.root,
|
|
305
|
+
!flattenInGroup && (isSolidSkeuomorphic(color) || isSecondarySkeuomorphic(color)) && nativeButtonInteraction.drop,
|
|
306
|
+
nativeButtonInteraction.colors[color],
|
|
307
|
+
isLinkType && "h-auto min-h-0 px-0 py-0",
|
|
308
|
+
// Web applies disabled opacity only when disabled — not while loading.
|
|
309
|
+
disabled && buttonStyles.disabledOpacity[color],
|
|
310
|
+
className
|
|
311
|
+
),
|
|
312
|
+
...props,
|
|
313
|
+
children: ({ pressed }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
314
|
+
!flattenInGroup && isSolidSkeuomorphic(color) && /* @__PURE__ */ jsxs(View, { pointerEvents: "none", className: nativeButtonInteraction.clip, children: [
|
|
315
|
+
/* @__PURE__ */ jsx(View, { className: nativeButtonInteraction.insetRing }),
|
|
316
|
+
/* @__PURE__ */ jsx(View, { className: nativeButtonInteraction.bottomWeight }),
|
|
317
|
+
/* @__PURE__ */ jsx(View, { className: nativeButtonInteraction.topHighlight })
|
|
318
|
+
] }),
|
|
319
|
+
!flattenInGroup && isSecondarySkeuomorphic(color) && /* @__PURE__ */ jsx(View, { pointerEvents: "none", className: nativeButtonInteraction.clip, children: /* @__PURE__ */ jsx(View, { className: nativeButtonInteraction.secondaryBottom }) }),
|
|
320
|
+
isValidElement(IconLeading) && !loading && IconLeading,
|
|
321
|
+
LeadingIcon && !loading && /* @__PURE__ */ jsx(LeadingIcon, { className: iconClassName, size: iconSizePx }),
|
|
322
|
+
loading && /* @__PURE__ */ jsx(
|
|
323
|
+
ButtonSpinner,
|
|
324
|
+
{
|
|
325
|
+
className: buttonStyles.colors[color].spinner,
|
|
326
|
+
size: iconSizePx,
|
|
327
|
+
showTextWhileLoading
|
|
328
|
+
}
|
|
329
|
+
),
|
|
330
|
+
showTitle && /* @__PURE__ */ jsx(
|
|
331
|
+
Text,
|
|
332
|
+
{
|
|
333
|
+
numberOfLines: 1,
|
|
334
|
+
className: cx(
|
|
335
|
+
buttonStyles.common.label,
|
|
336
|
+
buttonStyles.sizes[size].label,
|
|
337
|
+
buttonStyles.colors[color].label,
|
|
338
|
+
// Web link: transparent underline until hover — press ≈ hover on RN.
|
|
339
|
+
isLinkType && pressed && "underline",
|
|
340
|
+
padText && !isLinkType && "px-0.5",
|
|
341
|
+
loading && !showTextWhileLoading && "opacity-0"
|
|
342
|
+
),
|
|
343
|
+
children: titleText
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
!loading && customChildren,
|
|
347
|
+
isValidElement(IconTrailing) && !loading && IconTrailing,
|
|
348
|
+
TrailingIcon && !loading && /* @__PURE__ */ jsx(TrailingIcon, { className: iconClassName, size: iconSizePx })
|
|
349
|
+
] })
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
};
|
|
353
|
+
Button.displayName = "Button";
|
|
354
|
+
|
|
355
|
+
export { Button };
|
|
356
|
+
//# sourceMappingURL=button.js.map
|
|
357
|
+
//# sourceMappingURL=button.js.map
|