@gild-ui/react-native 0.0.0 → 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/Button.cjs +193 -0
- package/dist/Button.d.cts +3 -0
- package/dist/Button.d.mts +3 -0
- package/dist/Button.mjs +192 -0
- package/dist/Button.types-Bb9gBlbS.d.mts +1402 -0
- package/dist/Flex.cjs +18 -0
- package/dist/Flex.d.cts +2 -0
- package/dist/Flex.d.mts +2 -0
- package/dist/Flex.mjs +17 -0
- package/dist/Modal.cjs +56 -0
- package/dist/Modal.d.cts +7 -0
- package/dist/Modal.d.mts +7 -0
- package/dist/Modal.mjs +55 -0
- package/dist/TextInput.cjs +169 -0
- package/dist/TextInput.d.cts +3 -0
- package/dist/TextInput.d.mts +3 -0
- package/dist/TextInput.mjs +169 -0
- package/dist/ThemeProvider-BgTIjOfL.mjs +49 -0
- package/dist/ThemeProvider-CsfZi16_.cjs +53 -0
- package/dist/ThemeProvider.cjs +3 -0
- package/dist/ThemeProvider.d.cts +2 -0
- package/dist/ThemeProvider.d.mts +2 -0
- package/dist/ThemeProvider.mjs +1 -0
- package/dist/Typography.cjs +68 -0
- package/dist/Typography.d.cts +3 -0
- package/dist/Typography.d.mts +3 -0
- package/dist/Typography.mjs +68 -0
- package/dist/View-B1PzjpDr.cjs +76 -0
- package/dist/View-tHL6rDa8.mjs +65 -0
- package/dist/View.cjs +3 -0
- package/dist/View.d.cts +2 -0
- package/dist/View.d.mts +2 -0
- package/dist/View.mjs +1 -0
- package/dist/bridge-B_MGN7QY.d.mts +10 -0
- package/dist/bridge-CH-RnxIe.d.cts +10 -0
- package/dist/engine-CpEhmg4W.mjs +38 -0
- package/dist/engine-D9Z9l9JU.cjs +42 -0
- package/dist/engine.cjs +49 -0
- package/dist/engine.d.cts +66 -0
- package/dist/engine.d.mts +66 -0
- package/dist/engine.mjs +19 -0
- package/dist/exact-DOxXx2ZR.d.cts +9 -0
- package/dist/exact-DOxXx2ZR.d.mts +9 -0
- package/dist/index-BqhozwWy.d.mts +41 -0
- package/dist/index-DcHJkXar.d.cts +41 -0
- package/dist/index.cjs +67 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.mjs +5 -0
- package/dist/phoneTheme-RIafDzgw.mjs +12 -0
- package/dist/phoneTheme-kvZTk6l5.cjs +29 -0
- package/dist/styled-CmWGOVKb.cjs +174 -0
- package/dist/styled-k66N0ABX.mjs +163 -0
- package/dist/themes-DK6h0IiW.d.cts +1402 -0
- package/dist/themes-rGHVhV5e.mjs +8 -0
- package/dist/useDefaultProps-1josiKIp.mjs +13 -0
- package/dist/useDefaultProps-DzaUOADT.cjs +18 -0
- package/dist/useTheme.cjs +8 -0
- package/dist/useTheme.d.cts +3 -0
- package/dist/useTheme.d.mts +3 -0
- package/dist/useTheme.mjs +1 -0
- package/package.json +168 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Masoud Soroush <https://soroush.tech>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/@gild-ui/react-native)
|
|
2
|
+
[](https://app.codecov.io/gh/soroush-tech/design-system?flags%5B0%5D=react-native)
|
|
3
|
+
[](./LICENSE)
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
## Gild UI for **React Native**
|
|
6
|
+
|
|
7
|
+
The components of [`@gild-ui/react`](../react) with the same names, props, slots and themes, drawn
|
|
8
|
+
with the platform views of iOS and Android. A theme is real values on a phone: `space[2]` is `16`, a
|
|
9
|
+
color is its hex.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @gild-ui/react-native @gild-ui/core
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It needs `react` `^19.2.8` and `react-native` `>=0.76.0`.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
// theme/themes.ts - the same file as on the web
|
|
19
|
+
import { baseTheme, createTheme, defineThemes } from '@gild-ui/core/theme'
|
|
20
|
+
|
|
21
|
+
export const themes = defineThemes({
|
|
22
|
+
light: createTheme(baseTheme, { name: 'light', colorScheme: 'light' }),
|
|
23
|
+
dark: createTheme(baseTheme, { name: 'dark', colorScheme: 'dark' }),
|
|
24
|
+
})
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// App.tsx
|
|
29
|
+
import { configure } from '@gild-ui/react-native/engine'
|
|
30
|
+
import { ThemeProvider } from '@gild-ui/react-native/ThemeProvider'
|
|
31
|
+
import { Button } from '@gild-ui/react-native/Button'
|
|
32
|
+
import { Flex } from '@gild-ui/react-native/Flex'
|
|
33
|
+
import { Typography } from '@gild-ui/react-native/Typography'
|
|
34
|
+
import { themes } from './theme/themes'
|
|
35
|
+
|
|
36
|
+
configure({ serverTheme: themes.light })
|
|
37
|
+
|
|
38
|
+
export default function App() {
|
|
39
|
+
return (
|
|
40
|
+
<ThemeProvider theme={themes.light}>
|
|
41
|
+
<Flex p={3} gap={2}>
|
|
42
|
+
<Typography variant="h1">Hello</Typography>
|
|
43
|
+
<Button onClick={() => console.log('pressed')}>Press</Button>
|
|
44
|
+
</Flex>
|
|
45
|
+
</ThemeProvider>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## What is in the first round
|
|
51
|
+
|
|
52
|
+
`ThemeProvider`, `useTheme`, `configure` (`@gild-ui/react-native/engine`), `View`, `Flex`,
|
|
53
|
+
`Typography`, `Button`, `TextInput` and `Modal`. Every other component of `@gild-ui/react` comes later.
|
|
54
|
+
Each component's README says what a phone does with each prop.
|
|
55
|
+
|
|
56
|
+
## How it maps the web's props
|
|
57
|
+
|
|
58
|
+
- **`aria-*` and `role`** go to the native element, which takes them from React Native 0.71 (`aria-label`,
|
|
59
|
+
`aria-hidden`, `aria-busy`, `aria-disabled`, `aria-live`, ... and `role`). An attribute React Native
|
|
60
|
+
has no form of (`aria-describedby`, `aria-controls`) is ignored by the platform.
|
|
61
|
+
- **`className` and `data-*`** are accepted and not passed on: a phone has no classes. `data-testid` is
|
|
62
|
+
`testID`.
|
|
63
|
+
- **`onClick`** is `onPress`; a text input's `onChange` gets an event with `target.value`.
|
|
64
|
+
- **Lengths** in `px` and `rem` are numbers. `em` has no meaning on a phone: a letter spacing in `em`
|
|
65
|
+
is read as 16 points an em, and any other `em` value is passed on as it is.
|
|
66
|
+
- **`style`** takes entries of the `StyleSheet` of this package (style objects), not web ones; it is the one
|
|
67
|
+
member of a component's props whose type differs from the web's.
|
|
68
|
+
|
|
69
|
+
## Run the example
|
|
70
|
+
|
|
71
|
+
`apps/native-example` is an Expo app with one screen that uses all six components and the switch between
|
|
72
|
+
two themes. From the repository root:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
pnpm --filter @gild-ui/react-native build
|
|
76
|
+
pnpm --filter @soroush.design/native-example web # the browser
|
|
77
|
+
pnpm --filter @soroush.design/native-example start # then scan the QR code with Expo Go
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`ios` and `android` start the simulators.
|
package/dist/Button.cjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_styled = require("./styled-CmWGOVKb.cjs");
|
|
3
|
+
const require_engine = require("./engine-D9Z9l9JU.cjs");
|
|
4
|
+
const require_useDefaultProps = require("./useDefaultProps-DzaUOADT.cjs");
|
|
5
|
+
let _umber_style_react_native = require("@umber-style/react-native");
|
|
6
|
+
let _gild_ui_core_theme = require("@gild-ui/core/theme");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_native = require("react-native");
|
|
10
|
+
let _soroush_tech_styled_system = require("@soroush.tech/styled-system");
|
|
11
|
+
let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
|
|
12
|
+
// ../react/src/ButtonGroup/ButtonGroupContext.ts
|
|
13
|
+
const ButtonGroupContext = (0, react.createContext)({});
|
|
14
|
+
// src/Button/Button.native.tsx
|
|
15
|
+
const shouldForwardProp = (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([
|
|
16
|
+
..._soroush_tech_styled_system_should_forward_prop.props,
|
|
17
|
+
"variant",
|
|
18
|
+
"size",
|
|
19
|
+
"shape",
|
|
20
|
+
"fullWidth",
|
|
21
|
+
"loading",
|
|
22
|
+
"loadingPosition",
|
|
23
|
+
"startIcon",
|
|
24
|
+
"endIcon",
|
|
25
|
+
"loadingIndicator"
|
|
26
|
+
]);
|
|
27
|
+
const ButtonLabel = require_styled.styled("span", {
|
|
28
|
+
name: "Button",
|
|
29
|
+
slot: "label",
|
|
30
|
+
label: "ButtonLabel",
|
|
31
|
+
shouldForwardProp: (prop) => ![
|
|
32
|
+
"invisible",
|
|
33
|
+
"variant",
|
|
34
|
+
"color",
|
|
35
|
+
"size"
|
|
36
|
+
].includes(prop),
|
|
37
|
+
systemProps: [_soroush_tech_styled_system.typography]
|
|
38
|
+
})(({ theme, variant = "contained", color, size, invisible }) => {
|
|
39
|
+
const { main, contrastText } = theme.palette[color];
|
|
40
|
+
return {
|
|
41
|
+
color: variant === "contained" ? contrastText : main,
|
|
42
|
+
fontSize: theme.fontSizes[theme.sizes[size].fontSize],
|
|
43
|
+
textTransform: "uppercase",
|
|
44
|
+
...invisible && { opacity: 0 }
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const LoadingCenter = require_styled.styled("div", {
|
|
48
|
+
name: "Button",
|
|
49
|
+
slot: "loader",
|
|
50
|
+
label: "ButtonLoader"
|
|
51
|
+
})({
|
|
52
|
+
position: "absolute",
|
|
53
|
+
top: 0,
|
|
54
|
+
right: 0,
|
|
55
|
+
bottom: 0,
|
|
56
|
+
left: 0,
|
|
57
|
+
alignItems: "center",
|
|
58
|
+
justifyContent: "center"
|
|
59
|
+
});
|
|
60
|
+
const ButtonIcon = require_styled.styled("div", {
|
|
61
|
+
name: "Button",
|
|
62
|
+
slot: "icon",
|
|
63
|
+
label: "ButtonIcon"
|
|
64
|
+
})({
|
|
65
|
+
alignItems: "center",
|
|
66
|
+
flexShrink: 0
|
|
67
|
+
});
|
|
68
|
+
const baseStyles = {
|
|
69
|
+
position: "relative",
|
|
70
|
+
flexDirection: "row",
|
|
71
|
+
alignItems: "center",
|
|
72
|
+
justifyContent: "center",
|
|
73
|
+
...(0, _umber_style_react_native.at)((0, _umber_style_react_native.state)("pressed"), {}),
|
|
74
|
+
...(0, _umber_style_react_native.at)((0, _umber_style_react_native.state)("disabled"), { opacity: .5 })
|
|
75
|
+
};
|
|
76
|
+
const sizeVariants = ({ theme, size }) => {
|
|
77
|
+
const s = theme.sizes[size];
|
|
78
|
+
return {
|
|
79
|
+
paddingTop: theme.space[s.paddingTop],
|
|
80
|
+
paddingBottom: theme.space[s.paddingBottom],
|
|
81
|
+
paddingLeft: theme.space[s.paddingLeft],
|
|
82
|
+
paddingRight: theme.space[s.paddingRight]
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const variantStyles = ({ variant = "contained", theme, color = (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary") }) => {
|
|
86
|
+
const { main, dark } = theme.palette[color];
|
|
87
|
+
const outline = {
|
|
88
|
+
borderWidth: theme.borderWidths.thin,
|
|
89
|
+
borderStyle: "solid"
|
|
90
|
+
};
|
|
91
|
+
if (variant === "contained") return {
|
|
92
|
+
backgroundColor: main,
|
|
93
|
+
...outline,
|
|
94
|
+
borderColor: "transparent",
|
|
95
|
+
...(0, _umber_style_react_native.at)((0, _umber_style_react_native.state)("pressed"), { backgroundColor: dark })
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
backgroundColor: "transparent",
|
|
99
|
+
...outline,
|
|
100
|
+
borderColor: variant === "outlined" ? main : "transparent",
|
|
101
|
+
...(0, _umber_style_react_native.at)((0, _umber_style_react_native.state)("pressed"), { backgroundColor: (0, require_engine.engine_exports.alpha)(main, .125) })
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
const shapeVariants = ({ shape = "square", theme }) => {
|
|
105
|
+
if (shape === "pill") return { borderRadius: 9999 };
|
|
106
|
+
if (shape === "rounded") return { borderRadius: theme.radii[(0, _gild_ui_core_theme.themeDefault)(theme, "borderRadius", "md")] };
|
|
107
|
+
return { borderRadius: 0 };
|
|
108
|
+
};
|
|
109
|
+
const fullWidthStyles = ({ fullWidth }) => fullWidth ? { width: "100%" } : {};
|
|
110
|
+
const safeLayout = ({ size: _size, ...props }) => (0, _soroush_tech_styled_system.layout)(props);
|
|
111
|
+
const ButtonRoot = require_styled.styled("button", {
|
|
112
|
+
name: "Button",
|
|
113
|
+
label: "Button",
|
|
114
|
+
shouldForwardProp,
|
|
115
|
+
systemProps: [
|
|
116
|
+
_soroush_tech_styled_system.space,
|
|
117
|
+
safeLayout,
|
|
118
|
+
_soroush_tech_styled_system.border
|
|
119
|
+
]
|
|
120
|
+
})(baseStyles, sizeVariants, variantStyles, shapeVariants, fullWidthStyles);
|
|
121
|
+
const Button = (0, react.forwardRef)(function Button({ variant, color, size, shape, gap = 1, fontFamily, fontSize, fontWeight = "bold", fontStyle, letterSpacing = "tight", lineHeight, textAlign, startIcon, endIcon, fullWidth, loading = false, loadingIndicator, loadingPosition = "center", children, disabled, href, onClick, style, className, slotProps, target: _target, rel: _rel, ...rest }, ref) {
|
|
122
|
+
const group = (0, react.useContext)(ButtonGroupContext);
|
|
123
|
+
const theme = (0, require_engine.engine_exports.useTheme)();
|
|
124
|
+
const dp = require_useDefaultProps.useDefaultProps("Button");
|
|
125
|
+
const resolvedVariant = variant ?? group.variant ?? dp.variant ?? (0, _gild_ui_core_theme.themeDefault)(theme, "buttonVariant", "contained");
|
|
126
|
+
const resolvedColor = color ?? group.color ?? dp.color ?? (0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary");
|
|
127
|
+
const resolvedSize = size ?? group.size ?? dp.size ?? (0, _gild_ui_core_theme.themeDefault)(theme, "size", "md");
|
|
128
|
+
const resolvedShape = shape ?? dp.shape ?? "square";
|
|
129
|
+
const resolvedFullWidth = fullWidth ?? group.fullWidth ?? false;
|
|
130
|
+
const resolvedDisabled = (disabled ?? group.disabled ?? false) || loading;
|
|
131
|
+
const { main, contrastText } = theme.palette[resolvedColor];
|
|
132
|
+
const text = Object.fromEntries(Object.entries({
|
|
133
|
+
fontFamily,
|
|
134
|
+
fontSize,
|
|
135
|
+
fontWeight,
|
|
136
|
+
fontStyle,
|
|
137
|
+
letterSpacing,
|
|
138
|
+
lineHeight,
|
|
139
|
+
textAlign
|
|
140
|
+
}).filter(([, value]) => value !== void 0));
|
|
141
|
+
const indicator = loadingIndicator ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.ActivityIndicator, {
|
|
142
|
+
size: "small",
|
|
143
|
+
color: resolvedVariant === "contained" ? contrastText : main
|
|
144
|
+
});
|
|
145
|
+
const isCenter = loading && loadingPosition === "center";
|
|
146
|
+
const start = loading && loadingPosition === "start" ? indicator : startIcon;
|
|
147
|
+
const end = loading && loadingPosition === "end" ? indicator : endIcon;
|
|
148
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ButtonRoot, {
|
|
149
|
+
ref,
|
|
150
|
+
role: href === void 0 ? "button" : "link",
|
|
151
|
+
variant: resolvedVariant,
|
|
152
|
+
color: resolvedColor,
|
|
153
|
+
size: resolvedSize,
|
|
154
|
+
shape: resolvedShape,
|
|
155
|
+
gap,
|
|
156
|
+
fullWidth: resolvedFullWidth,
|
|
157
|
+
disabled: resolvedDisabled,
|
|
158
|
+
"aria-busy": loading || void 0,
|
|
159
|
+
...rest,
|
|
160
|
+
...require_styled.mergeOverrides(slotProps?.root, {
|
|
161
|
+
style,
|
|
162
|
+
className
|
|
163
|
+
}),
|
|
164
|
+
onClick: (event) => {
|
|
165
|
+
if (href !== void 0) react_native.Linking.openURL(href);
|
|
166
|
+
onClick?.(event);
|
|
167
|
+
},
|
|
168
|
+
children: [
|
|
169
|
+
start != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ButtonIcon, {
|
|
170
|
+
...require_styled.mergeOverrides(slotProps?.icon),
|
|
171
|
+
children: start
|
|
172
|
+
}),
|
|
173
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ButtonLabel, {
|
|
174
|
+
variant: resolvedVariant,
|
|
175
|
+
color: resolvedColor,
|
|
176
|
+
size: resolvedSize,
|
|
177
|
+
invisible: isCenter,
|
|
178
|
+
...text,
|
|
179
|
+
...require_styled.mergeOverrides(slotProps?.label),
|
|
180
|
+
children
|
|
181
|
+
}),
|
|
182
|
+
isCenter && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingCenter, {
|
|
183
|
+
...require_styled.mergeOverrides(slotProps?.loader),
|
|
184
|
+
children: indicator
|
|
185
|
+
}),
|
|
186
|
+
end != null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ButtonIcon, {
|
|
187
|
+
...require_styled.mergeOverrides(slotProps?.icon),
|
|
188
|
+
children: end
|
|
189
|
+
})
|
|
190
|
+
]
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
exports.Button = Button;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { $ as ButtonVariant, G as ButtonColor, J as ButtonProps, K as ButtonLoadingPosition, Q as ButtonThemeConfig, X as ButtonSize, Y as ButtonShape, Z as ButtonSlot, et as GapToken, q as ButtonOwnerState } from "./themes-DK6h0IiW.cjs";
|
|
2
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
3
|
+
export type { ButtonColor, ButtonLoadingPosition, ButtonOwnerState, ButtonProps, ButtonShape, ButtonSize, ButtonSlot, ButtonThemeConfig, ButtonVariant, GapToken };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as ButtonShape, c as ButtonThemeConfig, i as ButtonProps, l as ButtonVariant, n as ButtonLoadingPosition, o as ButtonSize, r as ButtonOwnerState, s as ButtonSlot, t as ButtonColor, u as GapToken } from "./Button.types-Bb9gBlbS.mjs";
|
|
2
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
3
|
+
export type { ButtonColor, ButtonLoadingPosition, ButtonOwnerState, ButtonProps, ButtonShape, ButtonSize, ButtonSlot, ButtonThemeConfig, ButtonVariant, GapToken };
|
package/dist/Button.mjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { n as mergeOverrides, t as styled$1 } from "./styled-k66N0ABX.mjs";
|
|
2
|
+
import { t as engine_exports } from "./engine-CpEhmg4W.mjs";
|
|
3
|
+
import { t as useDefaultProps } from "./useDefaultProps-1josiKIp.mjs";
|
|
4
|
+
import { at, state } from "@umber-style/react-native";
|
|
5
|
+
import { themeDefault } from "@gild-ui/core/theme";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { createContext, forwardRef, useContext } from "react";
|
|
8
|
+
import { ActivityIndicator, Linking } from "react-native";
|
|
9
|
+
import { border, layout, space, typography } from "@soroush.tech/styled-system";
|
|
10
|
+
import { createShouldForwardProp, props } from "@soroush.tech/styled-system/should-forward-prop";
|
|
11
|
+
// ../react/src/ButtonGroup/ButtonGroupContext.ts
|
|
12
|
+
const ButtonGroupContext = createContext({});
|
|
13
|
+
// src/Button/Button.native.tsx
|
|
14
|
+
const shouldForwardProp = createShouldForwardProp([
|
|
15
|
+
...props,
|
|
16
|
+
"variant",
|
|
17
|
+
"size",
|
|
18
|
+
"shape",
|
|
19
|
+
"fullWidth",
|
|
20
|
+
"loading",
|
|
21
|
+
"loadingPosition",
|
|
22
|
+
"startIcon",
|
|
23
|
+
"endIcon",
|
|
24
|
+
"loadingIndicator"
|
|
25
|
+
]);
|
|
26
|
+
const ButtonLabel = styled$1("span", {
|
|
27
|
+
name: "Button",
|
|
28
|
+
slot: "label",
|
|
29
|
+
label: "ButtonLabel",
|
|
30
|
+
shouldForwardProp: (prop) => ![
|
|
31
|
+
"invisible",
|
|
32
|
+
"variant",
|
|
33
|
+
"color",
|
|
34
|
+
"size"
|
|
35
|
+
].includes(prop),
|
|
36
|
+
systemProps: [typography]
|
|
37
|
+
})(({ theme, variant = "contained", color, size, invisible }) => {
|
|
38
|
+
const { main, contrastText } = theme.palette[color];
|
|
39
|
+
return {
|
|
40
|
+
color: variant === "contained" ? contrastText : main,
|
|
41
|
+
fontSize: theme.fontSizes[theme.sizes[size].fontSize],
|
|
42
|
+
textTransform: "uppercase",
|
|
43
|
+
...invisible && { opacity: 0 }
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const LoadingCenter = styled$1("div", {
|
|
47
|
+
name: "Button",
|
|
48
|
+
slot: "loader",
|
|
49
|
+
label: "ButtonLoader"
|
|
50
|
+
})({
|
|
51
|
+
position: "absolute",
|
|
52
|
+
top: 0,
|
|
53
|
+
right: 0,
|
|
54
|
+
bottom: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
justifyContent: "center"
|
|
58
|
+
});
|
|
59
|
+
const ButtonIcon = styled$1("div", {
|
|
60
|
+
name: "Button",
|
|
61
|
+
slot: "icon",
|
|
62
|
+
label: "ButtonIcon"
|
|
63
|
+
})({
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
flexShrink: 0
|
|
66
|
+
});
|
|
67
|
+
const baseStyles = {
|
|
68
|
+
position: "relative",
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
justifyContent: "center",
|
|
72
|
+
...at(state("pressed"), {}),
|
|
73
|
+
...at(state("disabled"), { opacity: .5 })
|
|
74
|
+
};
|
|
75
|
+
const sizeVariants = ({ theme, size }) => {
|
|
76
|
+
const s = theme.sizes[size];
|
|
77
|
+
return {
|
|
78
|
+
paddingTop: theme.space[s.paddingTop],
|
|
79
|
+
paddingBottom: theme.space[s.paddingBottom],
|
|
80
|
+
paddingLeft: theme.space[s.paddingLeft],
|
|
81
|
+
paddingRight: theme.space[s.paddingRight]
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const variantStyles = ({ variant = "contained", theme, color = themeDefault(theme, "color", "primary") }) => {
|
|
85
|
+
const { main, dark } = theme.palette[color];
|
|
86
|
+
const outline = {
|
|
87
|
+
borderWidth: theme.borderWidths.thin,
|
|
88
|
+
borderStyle: "solid"
|
|
89
|
+
};
|
|
90
|
+
if (variant === "contained") return {
|
|
91
|
+
backgroundColor: main,
|
|
92
|
+
...outline,
|
|
93
|
+
borderColor: "transparent",
|
|
94
|
+
...at(state("pressed"), { backgroundColor: dark })
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
backgroundColor: "transparent",
|
|
98
|
+
...outline,
|
|
99
|
+
borderColor: variant === "outlined" ? main : "transparent",
|
|
100
|
+
...at(state("pressed"), { backgroundColor: (0, engine_exports.alpha)(main, .125) })
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
const shapeVariants = ({ shape = "square", theme }) => {
|
|
104
|
+
if (shape === "pill") return { borderRadius: 9999 };
|
|
105
|
+
if (shape === "rounded") return { borderRadius: theme.radii[themeDefault(theme, "borderRadius", "md")] };
|
|
106
|
+
return { borderRadius: 0 };
|
|
107
|
+
};
|
|
108
|
+
const fullWidthStyles = ({ fullWidth }) => fullWidth ? { width: "100%" } : {};
|
|
109
|
+
const safeLayout = ({ size: _size, ...props }) => layout(props);
|
|
110
|
+
const ButtonRoot = styled$1("button", {
|
|
111
|
+
name: "Button",
|
|
112
|
+
label: "Button",
|
|
113
|
+
shouldForwardProp,
|
|
114
|
+
systemProps: [
|
|
115
|
+
space,
|
|
116
|
+
safeLayout,
|
|
117
|
+
border
|
|
118
|
+
]
|
|
119
|
+
})(baseStyles, sizeVariants, variantStyles, shapeVariants, fullWidthStyles);
|
|
120
|
+
const Button = forwardRef(function Button({ variant, color, size, shape, gap = 1, fontFamily, fontSize, fontWeight = "bold", fontStyle, letterSpacing = "tight", lineHeight, textAlign, startIcon, endIcon, fullWidth, loading = false, loadingIndicator, loadingPosition = "center", children, disabled, href, onClick, style, className, slotProps, target: _target, rel: _rel, ...rest }, ref) {
|
|
121
|
+
const group = useContext(ButtonGroupContext);
|
|
122
|
+
const theme = (0, engine_exports.useTheme)();
|
|
123
|
+
const dp = useDefaultProps("Button");
|
|
124
|
+
const resolvedVariant = variant ?? group.variant ?? dp.variant ?? themeDefault(theme, "buttonVariant", "contained");
|
|
125
|
+
const resolvedColor = color ?? group.color ?? dp.color ?? themeDefault(theme, "color", "primary");
|
|
126
|
+
const resolvedSize = size ?? group.size ?? dp.size ?? themeDefault(theme, "size", "md");
|
|
127
|
+
const resolvedShape = shape ?? dp.shape ?? "square";
|
|
128
|
+
const resolvedFullWidth = fullWidth ?? group.fullWidth ?? false;
|
|
129
|
+
const resolvedDisabled = (disabled ?? group.disabled ?? false) || loading;
|
|
130
|
+
const { main, contrastText } = theme.palette[resolvedColor];
|
|
131
|
+
const text = Object.fromEntries(Object.entries({
|
|
132
|
+
fontFamily,
|
|
133
|
+
fontSize,
|
|
134
|
+
fontWeight,
|
|
135
|
+
fontStyle,
|
|
136
|
+
letterSpacing,
|
|
137
|
+
lineHeight,
|
|
138
|
+
textAlign
|
|
139
|
+
}).filter(([, value]) => value !== void 0));
|
|
140
|
+
const indicator = loadingIndicator ?? /* @__PURE__ */ jsx(ActivityIndicator, {
|
|
141
|
+
size: "small",
|
|
142
|
+
color: resolvedVariant === "contained" ? contrastText : main
|
|
143
|
+
});
|
|
144
|
+
const isCenter = loading && loadingPosition === "center";
|
|
145
|
+
const start = loading && loadingPosition === "start" ? indicator : startIcon;
|
|
146
|
+
const end = loading && loadingPosition === "end" ? indicator : endIcon;
|
|
147
|
+
return /* @__PURE__ */ jsxs(ButtonRoot, {
|
|
148
|
+
ref,
|
|
149
|
+
role: href === void 0 ? "button" : "link",
|
|
150
|
+
variant: resolvedVariant,
|
|
151
|
+
color: resolvedColor,
|
|
152
|
+
size: resolvedSize,
|
|
153
|
+
shape: resolvedShape,
|
|
154
|
+
gap,
|
|
155
|
+
fullWidth: resolvedFullWidth,
|
|
156
|
+
disabled: resolvedDisabled,
|
|
157
|
+
"aria-busy": loading || void 0,
|
|
158
|
+
...rest,
|
|
159
|
+
...mergeOverrides(slotProps?.root, {
|
|
160
|
+
style,
|
|
161
|
+
className
|
|
162
|
+
}),
|
|
163
|
+
onClick: (event) => {
|
|
164
|
+
if (href !== void 0) Linking.openURL(href);
|
|
165
|
+
onClick?.(event);
|
|
166
|
+
},
|
|
167
|
+
children: [
|
|
168
|
+
start != null && /* @__PURE__ */ jsx(ButtonIcon, {
|
|
169
|
+
...mergeOverrides(slotProps?.icon),
|
|
170
|
+
children: start
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ jsx(ButtonLabel, {
|
|
173
|
+
variant: resolvedVariant,
|
|
174
|
+
color: resolvedColor,
|
|
175
|
+
size: resolvedSize,
|
|
176
|
+
invisible: isCenter,
|
|
177
|
+
...text,
|
|
178
|
+
...mergeOverrides(slotProps?.label),
|
|
179
|
+
children
|
|
180
|
+
}),
|
|
181
|
+
isCenter && /* @__PURE__ */ jsx(LoadingCenter, {
|
|
182
|
+
...mergeOverrides(slotProps?.loader),
|
|
183
|
+
children: indicator
|
|
184
|
+
}),
|
|
185
|
+
end != null && /* @__PURE__ */ jsx(ButtonIcon, {
|
|
186
|
+
...mergeOverrides(slotProps?.icon),
|
|
187
|
+
children: end
|
|
188
|
+
})
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
export { Button };
|