@cdx-ui/components 0.0.1-beta.65 → 0.0.1-beta.66
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/lib/commonjs/components/AlertDialog/index.js +12 -10
- package/lib/commonjs/components/AlertDialog/index.js.map +1 -1
- package/lib/commonjs/components/Avatar/index.js +125 -25
- package/lib/commonjs/components/Avatar/index.js.map +1 -1
- package/lib/commonjs/components/Button/index.js +127 -28
- package/lib/commonjs/components/Button/index.js.map +1 -1
- package/lib/commonjs/components/Button/styles.js +9 -3
- package/lib/commonjs/components/Button/styles.js.map +1 -1
- package/lib/commonjs/components/CLAUDE.md +115 -11
- package/lib/commonjs/components/Checkbox/index.js +69 -22
- package/lib/commonjs/components/Checkbox/index.js.map +1 -1
- package/lib/commonjs/components/Checkbox/styles.js +1 -1
- package/lib/commonjs/components/Checkbox/styles.js.map +1 -1
- package/lib/commonjs/components/Chip/index.js +44 -36
- package/lib/commonjs/components/Chip/index.js.map +1 -1
- package/lib/commonjs/components/Chip/styles.js +6 -35
- package/lib/commonjs/components/Chip/styles.js.map +1 -1
- package/lib/commonjs/components/Dialog/index.js +92 -72
- package/lib/commonjs/components/Dialog/index.js.map +1 -1
- package/lib/commonjs/components/Field/index.js +70 -26
- package/lib/commonjs/components/Field/index.js.map +1 -1
- package/lib/commonjs/components/Form/index.js +5 -12
- package/lib/commonjs/components/Form/index.js.map +1 -1
- package/lib/commonjs/components/IconButton/index.js +5 -33
- package/lib/commonjs/components/IconButton/index.js.map +1 -1
- package/lib/commonjs/components/Input/index.js +50 -20
- package/lib/commonjs/components/Input/index.js.map +1 -1
- package/lib/commonjs/components/Link/index.js +14 -7
- package/lib/commonjs/components/Link/index.js.map +1 -1
- package/lib/commonjs/components/ListItem/index.js +129 -54
- package/lib/commonjs/components/ListItem/index.js.map +1 -1
- package/lib/commonjs/components/OtpInput/index.js +94 -28
- package/lib/commonjs/components/OtpInput/index.js.map +1 -1
- package/lib/commonjs/components/ProgressBar/index.js +8 -13
- package/lib/commonjs/components/ProgressBar/index.js.map +1 -1
- package/lib/commonjs/components/Radio/index.js +51 -53
- package/lib/commonjs/components/Radio/index.js.map +1 -1
- package/lib/commonjs/components/Select/index.js +112 -46
- package/lib/commonjs/components/Select/index.js.map +1 -1
- package/lib/commonjs/components/Select/styles.js +2 -2
- package/lib/commonjs/components/Select/styles.js.map +1 -1
- package/lib/commonjs/components/Switch/BaseSwitch.js +23 -13
- package/lib/commonjs/components/Switch/BaseSwitch.js.map +1 -1
- package/lib/commonjs/components/Switch/BaseSwitch.web.js +25 -21
- package/lib/commonjs/components/Switch/BaseSwitch.web.js.map +1 -1
- package/lib/commonjs/components/Switch/index.js +34 -3
- package/lib/commonjs/components/Switch/index.js.map +1 -1
- package/lib/commonjs/components/Tile/index.js +150 -77
- package/lib/commonjs/components/Tile/index.js.map +1 -1
- package/lib/commonjs/figma/Chip.figma.js +2 -2
- package/lib/commonjs/figma/Chip.figma.js.map +1 -1
- package/lib/commonjs/utils/positionToDataIcon.js +41 -0
- package/lib/commonjs/utils/positionToDataIcon.js.map +1 -0
- package/lib/module/components/AlertDialog/index.js +13 -11
- package/lib/module/components/AlertDialog/index.js.map +1 -1
- package/lib/module/components/Avatar/index.js +128 -28
- package/lib/module/components/Avatar/index.js.map +1 -1
- package/lib/module/components/Button/index.js +130 -32
- package/lib/module/components/Button/index.js.map +1 -1
- package/lib/module/components/Button/styles.js +8 -2
- package/lib/module/components/Button/styles.js.map +1 -1
- package/lib/module/components/CLAUDE.md +115 -11
- package/lib/module/components/Checkbox/index.js +72 -25
- package/lib/module/components/Checkbox/index.js.map +1 -1
- package/lib/module/components/Checkbox/styles.js +1 -1
- package/lib/module/components/Checkbox/styles.js.map +1 -1
- package/lib/module/components/Chip/index.js +47 -39
- package/lib/module/components/Chip/index.js.map +1 -1
- package/lib/module/components/Chip/styles.js +6 -35
- package/lib/module/components/Chip/styles.js.map +1 -1
- package/lib/module/components/Dialog/index.js +96 -76
- package/lib/module/components/Dialog/index.js.map +1 -1
- package/lib/module/components/Field/index.js +74 -31
- package/lib/module/components/Field/index.js.map +1 -1
- package/lib/module/components/Form/index.js +7 -14
- package/lib/module/components/Form/index.js.map +1 -1
- package/lib/module/components/IconButton/index.js +6 -34
- package/lib/module/components/IconButton/index.js.map +1 -1
- package/lib/module/components/Input/index.js +53 -23
- package/lib/module/components/Input/index.js.map +1 -1
- package/lib/module/components/Link/index.js +16 -8
- package/lib/module/components/Link/index.js.map +1 -1
- package/lib/module/components/ListItem/index.js +134 -59
- package/lib/module/components/ListItem/index.js.map +1 -1
- package/lib/module/components/OtpInput/index.js +94 -28
- package/lib/module/components/OtpInput/index.js.map +1 -1
- package/lib/module/components/ProgressBar/index.js +9 -14
- package/lib/module/components/ProgressBar/index.js.map +1 -1
- package/lib/module/components/Radio/index.js +54 -57
- package/lib/module/components/Radio/index.js.map +1 -1
- package/lib/module/components/Select/index.js +118 -52
- package/lib/module/components/Select/index.js.map +1 -1
- package/lib/module/components/Select/styles.js +2 -2
- package/lib/module/components/Select/styles.js.map +1 -1
- package/lib/module/components/Switch/BaseSwitch.js +24 -14
- package/lib/module/components/Switch/BaseSwitch.js.map +1 -1
- package/lib/module/components/Switch/BaseSwitch.web.js +26 -22
- package/lib/module/components/Switch/BaseSwitch.web.js.map +1 -1
- package/lib/module/components/Switch/index.js +35 -4
- package/lib/module/components/Switch/index.js.map +1 -1
- package/lib/module/components/Tile/index.js +155 -83
- package/lib/module/components/Tile/index.js.map +1 -1
- package/lib/module/figma/Chip.figma.js +2 -2
- package/lib/module/figma/Chip.figma.js.map +1 -1
- package/lib/module/utils/positionToDataIcon.js +38 -0
- package/lib/module/utils/positionToDataIcon.js.map +1 -0
- package/lib/typescript/components/AlertDialog/index.d.ts.map +1 -1
- package/lib/typescript/components/Avatar/index.d.ts +6 -2
- package/lib/typescript/components/Avatar/index.d.ts.map +1 -1
- package/lib/typescript/components/Button/index.d.ts +31 -8
- package/lib/typescript/components/Button/index.d.ts.map +1 -1
- package/lib/typescript/components/Button/styles.d.ts +2 -1
- package/lib/typescript/components/Button/styles.d.ts.map +1 -1
- package/lib/typescript/components/Checkbox/index.d.ts +3 -1
- package/lib/typescript/components/Checkbox/index.d.ts.map +1 -1
- package/lib/typescript/components/Chip/index.d.ts +19 -9
- package/lib/typescript/components/Chip/index.d.ts.map +1 -1
- package/lib/typescript/components/Chip/styles.d.ts +0 -1
- package/lib/typescript/components/Chip/styles.d.ts.map +1 -1
- package/lib/typescript/components/Dialog/index.d.ts +12 -6
- package/lib/typescript/components/Dialog/index.d.ts.map +1 -1
- package/lib/typescript/components/Dialog/styles.d.ts +1 -1
- package/lib/typescript/components/Field/index.d.ts +14 -7
- package/lib/typescript/components/Field/index.d.ts.map +1 -1
- package/lib/typescript/components/Form/index.d.ts +4 -4
- package/lib/typescript/components/Form/index.d.ts.map +1 -1
- package/lib/typescript/components/IconButton/index.d.ts.map +1 -1
- package/lib/typescript/components/Input/index.d.ts +11 -3
- package/lib/typescript/components/Input/index.d.ts.map +1 -1
- package/lib/typescript/components/Link/index.d.ts +2 -0
- package/lib/typescript/components/Link/index.d.ts.map +1 -1
- package/lib/typescript/components/ListItem/index.d.ts +28 -6
- package/lib/typescript/components/ListItem/index.d.ts.map +1 -1
- package/lib/typescript/components/OtpInput/index.d.ts +1 -1
- package/lib/typescript/components/OtpInput/index.d.ts.map +1 -1
- package/lib/typescript/components/ProgressBar/index.d.ts +4 -4
- package/lib/typescript/components/ProgressBar/index.d.ts.map +1 -1
- package/lib/typescript/components/Radio/index.d.ts +4 -0
- package/lib/typescript/components/Radio/index.d.ts.map +1 -1
- package/lib/typescript/components/Select/index.d.ts +35 -2
- package/lib/typescript/components/Select/index.d.ts.map +1 -1
- package/lib/typescript/components/Select/styles.d.ts.map +1 -1
- package/lib/typescript/components/Switch/BaseSwitch.d.ts +12 -5
- package/lib/typescript/components/Switch/BaseSwitch.d.ts.map +1 -1
- package/lib/typescript/components/Switch/BaseSwitch.web.d.ts +11 -5
- package/lib/typescript/components/Switch/BaseSwitch.web.d.ts.map +1 -1
- package/lib/typescript/components/Switch/index.d.ts +5 -1
- package/lib/typescript/components/Switch/index.d.ts.map +1 -1
- package/lib/typescript/components/Tile/index.d.ts +8 -2
- package/lib/typescript/components/Tile/index.d.ts.map +1 -1
- package/lib/typescript/utils/positionToDataIcon.d.ts +29 -0
- package/lib/typescript/utils/positionToDataIcon.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/components/AlertDialog/index.tsx +13 -14
- package/src/components/Avatar/index.tsx +134 -44
- package/src/components/Button/index.tsx +216 -44
- package/src/components/Button/styles.ts +50 -38
- package/src/components/CLAUDE.md +115 -11
- package/src/components/Checkbox/index.tsx +93 -32
- package/src/components/Checkbox/styles.ts +1 -1
- package/src/components/Chip/index.tsx +88 -61
- package/src/components/Chip/styles.ts +6 -18
- package/src/components/Dialog/index.tsx +139 -99
- package/src/components/Field/index.tsx +113 -49
- package/src/components/Form/index.tsx +18 -14
- package/src/components/IconButton/index.tsx +7 -31
- package/src/components/Input/index.tsx +75 -32
- package/src/components/Link/index.tsx +38 -12
- package/src/components/ListItem/index.tsx +158 -73
- package/src/components/OtpInput/index.tsx +126 -43
- package/src/components/ProgressBar/index.tsx +11 -16
- package/src/components/Radio/index.tsx +76 -54
- package/src/components/Select/index.tsx +174 -59
- package/src/components/Select/styles.ts +1 -2
- package/src/components/Switch/BaseSwitch.tsx +38 -16
- package/src/components/Switch/BaseSwitch.web.tsx +28 -35
- package/src/components/Switch/index.tsx +51 -4
- package/src/components/Tile/index.tsx +145 -94
- package/src/utils/positionToDataIcon.ts +34 -0
- package/lib/commonjs/components/Field/FieldLabel.js +0 -33
- package/lib/commonjs/components/Field/FieldLabel.js.map +0 -1
- package/lib/commonjs/components/Field/FieldLabel.web.js +0 -22
- package/lib/commonjs/components/Field/FieldLabel.web.js.map +0 -1
- package/lib/commonjs/components/Form/FormRoot.js +0 -25
- package/lib/commonjs/components/Form/FormRoot.js.map +0 -1
- package/lib/commonjs/components/Form/FormRoot.web.js +0 -17
- package/lib/commonjs/components/Form/FormRoot.web.js.map +0 -1
- package/lib/commonjs/components/Input/BaseInput.android.js +0 -20
- package/lib/commonjs/components/Input/BaseInput.android.js.map +0 -1
- package/lib/commonjs/components/Input/BaseInput.js +0 -13
- package/lib/commonjs/components/Input/BaseInput.js.map +0 -1
- package/lib/commonjs/components/Input/BaseInput.web.js +0 -50
- package/lib/commonjs/components/Input/BaseInput.web.js.map +0 -1
- package/lib/commonjs/components/Select/SelectTriggerHost.js +0 -10
- package/lib/commonjs/components/Select/SelectTriggerHost.js.map +0 -1
- package/lib/commonjs/components/Select/SelectTriggerHost.web.js +0 -102
- package/lib/commonjs/components/Select/SelectTriggerHost.web.js.map +0 -1
- package/lib/module/components/Field/FieldLabel.js +0 -29
- package/lib/module/components/Field/FieldLabel.js.map +0 -1
- package/lib/module/components/Field/FieldLabel.web.js +0 -17
- package/lib/module/components/Field/FieldLabel.web.js.map +0 -1
- package/lib/module/components/Form/FormRoot.js +0 -21
- package/lib/module/components/Form/FormRoot.js.map +0 -1
- package/lib/module/components/Form/FormRoot.web.js +0 -12
- package/lib/module/components/Form/FormRoot.web.js.map +0 -1
- package/lib/module/components/Input/BaseInput.android.js +0 -16
- package/lib/module/components/Input/BaseInput.android.js.map +0 -1
- package/lib/module/components/Input/BaseInput.js +0 -4
- package/lib/module/components/Input/BaseInput.js.map +0 -1
- package/lib/module/components/Input/BaseInput.web.js +0 -45
- package/lib/module/components/Input/BaseInput.web.js.map +0 -1
- package/lib/module/components/Select/SelectTriggerHost.js +0 -7
- package/lib/module/components/Select/SelectTriggerHost.js.map +0 -1
- package/lib/module/components/Select/SelectTriggerHost.web.js +0 -97
- package/lib/module/components/Select/SelectTriggerHost.web.js.map +0 -1
- package/lib/typescript/components/Field/FieldLabel.d.ts +0 -18
- package/lib/typescript/components/Field/FieldLabel.d.ts.map +0 -1
- package/lib/typescript/components/Field/FieldLabel.web.d.ts +0 -16
- package/lib/typescript/components/Field/FieldLabel.web.d.ts.map +0 -1
- package/lib/typescript/components/Form/FormRoot.d.ts +0 -14
- package/lib/typescript/components/Form/FormRoot.d.ts.map +0 -1
- package/lib/typescript/components/Form/FormRoot.web.d.ts +0 -10
- package/lib/typescript/components/Form/FormRoot.web.d.ts.map +0 -1
- package/lib/typescript/components/Input/BaseInput.android.d.ts +0 -3
- package/lib/typescript/components/Input/BaseInput.android.d.ts.map +0 -1
- package/lib/typescript/components/Input/BaseInput.d.ts +0 -2
- package/lib/typescript/components/Input/BaseInput.d.ts.map +0 -1
- package/lib/typescript/components/Input/BaseInput.web.d.ts +0 -3
- package/lib/typescript/components/Input/BaseInput.web.d.ts.map +0 -1
- package/lib/typescript/components/Select/SelectTriggerHost.d.ts +0 -3
- package/lib/typescript/components/Select/SelectTriggerHost.d.ts.map +0 -1
- package/lib/typescript/components/Select/SelectTriggerHost.web.d.ts +0 -16
- package/lib/typescript/components/Select/SelectTriggerHost.web.d.ts.map +0 -1
- package/src/components/Field/FieldLabel.tsx +0 -33
- package/src/components/Field/FieldLabel.web.tsx +0 -25
- package/src/components/Form/FormRoot.tsx +0 -20
- package/src/components/Form/FormRoot.web.tsx +0 -12
- package/src/components/Input/BaseInput.android.tsx +0 -13
- package/src/components/Input/BaseInput.tsx +0 -1
- package/src/components/Input/BaseInput.web.tsx +0 -41
- package/src/components/Select/SelectTriggerHost.tsx +0 -4
- package/src/components/Select/SelectTriggerHost.web.tsx +0 -143
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.positionToDataIcon = positionToDataIcon;
|
|
7
|
+
var _primitives = require("@cdx-ui/primitives");
|
|
8
|
+
/**
|
|
9
|
+
* Position hint accepted by icon/spinner-bearing styled slots
|
|
10
|
+
* (`Button.Icon`, `Button.Spinner`, `Chip.Icon`, etc.). Maps to a logical
|
|
11
|
+
* `data-icon` attribute that CVA targets for leading/trailing padding.
|
|
12
|
+
*
|
|
13
|
+
* `'leading'` → `data-icon="inline-start"`
|
|
14
|
+
* `'trailing'` → `data-icon="inline-end"`
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the data-attribute spread props for the requested position, or
|
|
19
|
+
* `undefined` when no position is set (so the attribute is omitted entirely
|
|
20
|
+
* and baseline spacing applies).
|
|
21
|
+
*
|
|
22
|
+
* Spread the result onto the rendered element:
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <Icon {...positionToDataIcon(position)} />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Spacing rules live in CVA variant strings, targeting the attribute via
|
|
29
|
+
* logical-property utilities so RTL flips automatically:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* cva(['data-[icon=inline-start]:me-1.5 data-[icon=inline-end]:ms-1.5'], { ... });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function positionToDataIcon(position) {
|
|
36
|
+
if (!position) return undefined;
|
|
37
|
+
return (0, _primitives.dataAttributes)({
|
|
38
|
+
icon: position === 'leading' ? 'inline-start' : 'inline-end'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=positionToDataIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_primitives","require","positionToDataIcon","position","undefined","dataAttributes","icon"],"sourceRoot":"../../../src","sources":["utils/positionToDataIcon.ts"],"mappings":";;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,kBAAkBA,CAACC,QAA2B,EAAE;EAC9D,IAAI,CAACA,QAAQ,EAAE,OAAOC,SAAS;EAC/B,OAAO,IAAAC,0BAAc,EAAC;IAAEC,IAAI,EAAEH,QAAQ,KAAK,SAAS,GAAG,cAAc,GAAG;EAAa,CAAC,CAAC;AACzF","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import React, { forwardRef } from 'react';
|
|
4
|
-
import { useDialog } from '@cdx-ui/primitives';
|
|
4
|
+
import { Slot, useDialog } from '@cdx-ui/primitives';
|
|
5
5
|
import { composeEventHandlers } from '@cdx-ui/utils';
|
|
6
6
|
import { Button } from '../Button';
|
|
7
7
|
import { Dialog } from '../Dialog';
|
|
@@ -37,11 +37,12 @@ const AlertDialogAction = /*#__PURE__*/forwardRef(({
|
|
|
37
37
|
className,
|
|
38
38
|
...props
|
|
39
39
|
}, ref) => {
|
|
40
|
-
if (asChild
|
|
41
|
-
return /*#__PURE__*/
|
|
42
|
-
ref,
|
|
43
|
-
className,
|
|
44
|
-
...props
|
|
40
|
+
if (asChild) {
|
|
41
|
+
return /*#__PURE__*/_jsx(Slot, {
|
|
42
|
+
ref: ref,
|
|
43
|
+
className: className,
|
|
44
|
+
...props,
|
|
45
|
+
children: children
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
return /*#__PURE__*/_jsx(Button, {
|
|
@@ -72,12 +73,13 @@ const AlertDialogCancel = /*#__PURE__*/forwardRef(({
|
|
|
72
73
|
onOpenChange
|
|
73
74
|
} = useDialog();
|
|
74
75
|
const handlePress = composeEventHandlers(onPress, () => onOpenChange(false));
|
|
75
|
-
if (asChild
|
|
76
|
-
return /*#__PURE__*/
|
|
77
|
-
ref,
|
|
76
|
+
if (asChild) {
|
|
77
|
+
return /*#__PURE__*/_jsx(Slot, {
|
|
78
|
+
ref: ref,
|
|
78
79
|
onPress: handlePress,
|
|
79
|
-
className,
|
|
80
|
-
...props
|
|
80
|
+
className: className,
|
|
81
|
+
...props,
|
|
82
|
+
children: children
|
|
81
83
|
});
|
|
82
84
|
}
|
|
83
85
|
return /*#__PURE__*/_jsx(Button, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","forwardRef","useDialog","composeEventHandlers","Button","Dialog","jsx","_jsx","AlertDialogRoot","closeOnBackdropPress","closeOnEscKey","role","children","props","ref","displayName","AlertDialogAction","asChild","color","className","
|
|
1
|
+
{"version":3,"names":["React","forwardRef","Slot","useDialog","composeEventHandlers","Button","Dialog","jsx","_jsx","AlertDialogRoot","closeOnBackdropPress","closeOnEscKey","role","children","props","ref","displayName","AlertDialogAction","asChild","color","className","variant","Label","AlertDialogCancel","onPress","onOpenChange","handlePress","AlertDialog","Object","assign","Trigger","Popup","Header","Title","Description","Content","Text","Footer","Close","Action","Cancel"],"sourceRoot":"../../../../src","sources":["components/AlertDialog/index.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AAEzC,SAASC,IAAI,EAAEC,SAAS,QAAQ,oBAAoB;AACpD,SAASC,oBAAoB,QAAQ,eAAe;AACpD,SAASC,MAAM,QAA0B,WAAW;AACpD,SAASC,MAAM,QAA8B,WAAW;;AAExD;AACA;AACA;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAIA,MAAMC,eAAe,gBAAGR,UAAU,CAChC,CACE;EACES,oBAAoB,GAAG,KAAK;EAC5BC,aAAa,GAAG,KAAK;EACrBC,IAAI,GAAG,aAAa;EACpBC,QAAQ;EACR,GAAGC;AACL,CAAC,EACDC,GAAG,kBAEHP,IAAA,CAACF,MAAM;EACLS,GAAG,EAAEA,GAAI;EACTL,oBAAoB,EAAEA,oBAAqB;EAC3CC,aAAa,EAAEA,aAAc;EAC7BC,IAAI,EAAEA,IAAK;EAAA,GACPE,KAAK;EAAAD,QAAA,EAERA;AAAQ,CACH,CAEZ,CAAC;AACDJ,eAAe,CAACO,WAAW,GAAG,aAAa;;AAE3C;AACA;AACA;;AAMA,MAAMC,iBAAiB,gBAAGhB,UAAU,CAClC,CAAC;EAAEiB,O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AY;IAACN,SAAS,EAAEA,SAAU;IAAA,GAAKN,KAAK;IAAAD,QAAA,eACrFL,IAAA,CAACH,MAAM,CAACiB,KAAK;MAAAT,QAAA,EAAEA;IAAQ,CAAe;EAAC,CACjC,CAAC;AAEb,CACF,CAAC;AACDU,iBAAiB,CAACP,WAAW,GAAG,oBAAoB;;AAEpD;AACA;AACA;;AAgBA,OAAO,MAAMW,WAAW,GAAGC,MAAM,CAACC,MAAM,CAACpB,eAAe,EAAE;EACxDqB,OAAO,EAAExB,MAAM,CAACwB,OAAO;EACvBC,KAAK,EAAEzB,MAAM,CAACyB,KAAK;EACnBC,MAAM,EAAE1B,MAAM,CAAC0B,MAAM;EACrBC,KAAK,EAAE3B,MAAM,CAAC2B,KAAK;EACnBC,WAAW,EAAE5B,MAAM,CAAC4B,WAAW;EAC/BC,OAAO,EAAE7B,MAAM,CAAC6B,OAAO;EACvBC,IAAI,EAAE9B,MAAM,CAAC8B,IAAI;EACjBC,MAAM,EAAE/B,MAAM,CAAC+B,MAAM;EACrBC,KAAK,EAAEhC,MAAM,CAACgC,KAAK;EACnBC,MAAM,EAAEtB,iBAAiB;EACzBuB,MAAM,EAAEjB;AACV,CAAC,CAAiC","ignoreList":[]}
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { forwardRef } from 'react';
|
|
3
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
4
4
|
import { Image, Text, View } from 'react-native';
|
|
5
|
-
import {
|
|
6
|
-
import { cn,
|
|
5
|
+
import { AvatarRoot as AvatarRootPrimitive, Slot, dataAttributes, mergeDataAttributes, useAvatarContext } from '@cdx-ui/primitives';
|
|
6
|
+
import { cn, ParentContext, useParentContext, useStyleContext } from '@cdx-ui/utils';
|
|
7
7
|
import { Icon as IconComponent } from '../Icon';
|
|
8
8
|
import { avatarBadgeVariants, avatarIconVariants, avatarTextVariants, avatarImageVariants, avatarRootVariants } from './styles';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
const SCOPE = 'AVATAR';
|
|
11
|
-
const Root = withStyleContext(View, SCOPE);
|
|
12
11
|
const useAvatarStyleContext = () => useStyleContext(SCOPE);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// UTILITIES
|
|
15
|
+
// =============================================================================
|
|
16
|
+
|
|
17
|
+
function getInitials(name) {
|
|
18
|
+
const trimmed = name.trim();
|
|
19
|
+
const words = trimmed.split(/\s+/);
|
|
20
|
+
if (words.length === 1 && trimmed.length <= 2) {
|
|
21
|
+
return trimmed.toUpperCase();
|
|
22
|
+
}
|
|
23
|
+
let result = '';
|
|
24
|
+
for (const word of words) {
|
|
25
|
+
if (word.length > 0) {
|
|
26
|
+
result += word.charAt(0);
|
|
27
|
+
}
|
|
28
|
+
if (result.length >= 2) break;
|
|
29
|
+
}
|
|
30
|
+
return result.toUpperCase();
|
|
31
|
+
}
|
|
20
32
|
|
|
21
33
|
// =============================================================================
|
|
22
34
|
// AVATAR ROOT
|
|
@@ -32,15 +44,25 @@ const AvatarRoot = /*#__PURE__*/forwardRef(({
|
|
|
32
44
|
const computedClassName = cn(avatarRootVariants({
|
|
33
45
|
size
|
|
34
46
|
}), className);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
context: {
|
|
47
|
+
const parent = useParentContext();
|
|
48
|
+
const ctx = useMemo(() => ({
|
|
49
|
+
...parent,
|
|
50
|
+
[SCOPE]: {
|
|
40
51
|
size
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
}
|
|
53
|
+
}), [parent, size]);
|
|
54
|
+
return /*#__PURE__*/_jsx(ParentContext.Provider, {
|
|
55
|
+
value: ctx,
|
|
56
|
+
children: /*#__PURE__*/_jsx(AvatarRootPrimitive, {
|
|
57
|
+
ref: ref,
|
|
58
|
+
className: computedClassName,
|
|
59
|
+
style: style,
|
|
60
|
+
...props,
|
|
61
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
62
|
+
slot: 'avatar'
|
|
63
|
+
})),
|
|
64
|
+
children: children
|
|
65
|
+
})
|
|
44
66
|
});
|
|
45
67
|
});
|
|
46
68
|
AvatarRoot.displayName = 'Avatar';
|
|
@@ -50,16 +72,53 @@ AvatarRoot.displayName = 'Avatar';
|
|
|
50
72
|
// =============================================================================
|
|
51
73
|
|
|
52
74
|
const AvatarImage = /*#__PURE__*/forwardRef(({
|
|
75
|
+
asChild,
|
|
53
76
|
className,
|
|
54
77
|
style,
|
|
78
|
+
src,
|
|
79
|
+
source,
|
|
80
|
+
onLoad,
|
|
81
|
+
onError,
|
|
55
82
|
...props
|
|
56
83
|
}, ref) => {
|
|
84
|
+
const {
|
|
85
|
+
imageError,
|
|
86
|
+
setImageLoaded,
|
|
87
|
+
setImageError
|
|
88
|
+
} = useAvatarContext();
|
|
57
89
|
const computedClassName = cn(avatarImageVariants(), className);
|
|
58
|
-
|
|
90
|
+
const resolvedSource = useMemo(() => src ? {
|
|
91
|
+
uri: src
|
|
92
|
+
} : source, [src, source]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!resolvedSource) {
|
|
95
|
+
setImageError(true);
|
|
96
|
+
} else {
|
|
97
|
+
setImageError(false);
|
|
98
|
+
setImageLoaded(false);
|
|
99
|
+
}
|
|
100
|
+
}, [resolvedSource, setImageError, setImageLoaded]);
|
|
101
|
+
if (!resolvedSource || imageError) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const Comp = asChild ? Slot : Image;
|
|
105
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
59
106
|
ref: ref,
|
|
107
|
+
source: resolvedSource,
|
|
60
108
|
className: computedClassName,
|
|
61
109
|
style: style,
|
|
62
|
-
|
|
110
|
+
onLoad: e => {
|
|
111
|
+
setImageLoaded(true);
|
|
112
|
+
if (onLoad) onLoad(e);
|
|
113
|
+
},
|
|
114
|
+
onError: e => {
|
|
115
|
+
setImageError(true);
|
|
116
|
+
if (onError) onError(e);
|
|
117
|
+
},
|
|
118
|
+
...props,
|
|
119
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
120
|
+
slot: 'avatar-image'
|
|
121
|
+
}))
|
|
63
122
|
});
|
|
64
123
|
});
|
|
65
124
|
AvatarImage.displayName = 'Avatar.Image';
|
|
@@ -69,6 +128,7 @@ AvatarImage.displayName = 'Avatar.Image';
|
|
|
69
128
|
// =============================================================================
|
|
70
129
|
|
|
71
130
|
const AvatarText = /*#__PURE__*/forwardRef(({
|
|
131
|
+
asChild,
|
|
72
132
|
className,
|
|
73
133
|
children,
|
|
74
134
|
style,
|
|
@@ -77,15 +137,27 @@ const AvatarText = /*#__PURE__*/forwardRef(({
|
|
|
77
137
|
const {
|
|
78
138
|
size
|
|
79
139
|
} = useAvatarStyleContext();
|
|
140
|
+
const {
|
|
141
|
+
imageLoaded,
|
|
142
|
+
imageError
|
|
143
|
+
} = useAvatarContext();
|
|
144
|
+
const visible = !imageLoaded || imageError;
|
|
80
145
|
const computedClassName = cn(avatarTextVariants({
|
|
81
146
|
size
|
|
82
147
|
}), className);
|
|
83
|
-
|
|
148
|
+
const text = typeof children === 'string' ? getInitials(children) : children;
|
|
149
|
+
const Comp = asChild ? Slot : Text;
|
|
150
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
84
151
|
ref: ref,
|
|
85
152
|
className: computedClassName,
|
|
86
|
-
style: style,
|
|
153
|
+
style: [style, !visible && {
|
|
154
|
+
opacity: 0
|
|
155
|
+
}],
|
|
87
156
|
...props,
|
|
88
|
-
|
|
157
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
158
|
+
slot: 'avatar-text'
|
|
159
|
+
})),
|
|
160
|
+
children: text
|
|
89
161
|
});
|
|
90
162
|
});
|
|
91
163
|
AvatarText.displayName = 'Avatar.Text';
|
|
@@ -95,6 +167,7 @@ AvatarText.displayName = 'Avatar.Text';
|
|
|
95
167
|
// =============================================================================
|
|
96
168
|
|
|
97
169
|
const AvatarIcon = ({
|
|
170
|
+
asChild,
|
|
98
171
|
className,
|
|
99
172
|
style,
|
|
100
173
|
...props
|
|
@@ -102,13 +175,35 @@ const AvatarIcon = ({
|
|
|
102
175
|
const {
|
|
103
176
|
size
|
|
104
177
|
} = useAvatarStyleContext();
|
|
178
|
+
const {
|
|
179
|
+
imageLoaded,
|
|
180
|
+
imageError
|
|
181
|
+
} = useAvatarContext();
|
|
182
|
+
const visible = !imageLoaded || imageError;
|
|
105
183
|
const computedClassName = cn(avatarIconVariants({
|
|
106
184
|
size
|
|
107
185
|
}), className);
|
|
108
|
-
|
|
186
|
+
if (asChild) {
|
|
187
|
+
return /*#__PURE__*/_jsx(Slot, {
|
|
188
|
+
className: computedClassName,
|
|
189
|
+
style: [style, !visible && {
|
|
190
|
+
opacity: 0
|
|
191
|
+
}],
|
|
192
|
+
...props,
|
|
193
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
194
|
+
slot: 'avatar-icon'
|
|
195
|
+
}))
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return /*#__PURE__*/_jsx(IconComponent, {
|
|
109
199
|
className: computedClassName,
|
|
110
|
-
style: style,
|
|
111
|
-
|
|
200
|
+
style: [style, !visible && {
|
|
201
|
+
opacity: 0
|
|
202
|
+
}],
|
|
203
|
+
...props,
|
|
204
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
205
|
+
slot: 'avatar-icon'
|
|
206
|
+
}))
|
|
112
207
|
});
|
|
113
208
|
};
|
|
114
209
|
AvatarIcon.displayName = 'Avatar.Icon';
|
|
@@ -118,6 +213,7 @@ AvatarIcon.displayName = 'Avatar.Icon';
|
|
|
118
213
|
// =============================================================================
|
|
119
214
|
|
|
120
215
|
const AvatarBadge = /*#__PURE__*/forwardRef(({
|
|
216
|
+
asChild,
|
|
121
217
|
className,
|
|
122
218
|
children,
|
|
123
219
|
style,
|
|
@@ -129,11 +225,15 @@ const AvatarBadge = /*#__PURE__*/forwardRef(({
|
|
|
129
225
|
const computedClassName = cn(avatarBadgeVariants({
|
|
130
226
|
size
|
|
131
227
|
}), className);
|
|
132
|
-
|
|
228
|
+
const Comp = asChild ? Slot : View;
|
|
229
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
133
230
|
ref: ref,
|
|
134
231
|
className: computedClassName,
|
|
135
232
|
style: style,
|
|
136
233
|
...props,
|
|
234
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
235
|
+
slot: 'avatar-badge'
|
|
236
|
+
})),
|
|
137
237
|
children: children
|
|
138
238
|
});
|
|
139
239
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","Image","Text","View","
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useMemo","Image","Text","View","AvatarRoot","AvatarRootPrimitive","Slot","dataAttributes","mergeDataAttributes","useAvatarContext","cn","ParentContext","useParentContext","useStyleContext","Icon","IconComponent","avatarBadgeVariants","avatarIconVariants","avatarTextVariants","avatarImageVariants","avatarRootVariants","jsx","_jsx","SCOPE","useAvatarStyleContext","getInitials","name","trimmed","trim","words","split","length","toUpperCase","result","word","charAt","size","className","children","style","props","ref","computedClassName","parent","ctx","Provider","value","slot","displayName","AvatarImage","asChild","src","source","onLoad","onError","imageError","setImageLoaded","setImageError","resolvedSource","uri","Comp","e","AvatarText","imageLoaded","visible","text","opacity","AvatarIcon","AvatarBadge","Avatar","Object","assign","Badge"],"sourceRoot":"../../../../src","sources":["components/Avatar/index.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAwB,OAAO;AACtE,SAASC,KAAK,EAAEC,IAAI,EAAEC,IAAI,QAAyD,cAAc;AACjG,SACEC,UAAU,IAAIC,mBAAmB,EACjCC,IAAI,EACJC,cAAc,EACdC,mBAAmB,EACnBC,gBAAgB,QAGX,oBAAoB;AAC3B,SA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,WAAW,GAAG,cAAc;;AAExC;AACA;AACA;;AASA,OAAO,MAAMqB,MAAM,GAAGC,MAAM,CAACC,MAAM,CAACnE,UAAU,EAAE;EAC9CH,KAAK,EAAEgD,WAAW;EAClB/C,IAAI,EAAE4D,UAAU;EAChBhD,IAAI,EAAEqD,UAAU;EAChBK,KAAK,EAAEJ;AACT,CAAC,CAA4B","ignoreList":[]}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { forwardRef, useEffect } from 'react';
|
|
4
|
-
import { ActivityIndicator,
|
|
5
|
-
import {
|
|
6
|
-
import { cn,
|
|
3
|
+
import React, { forwardRef, useEffect, useMemo } from 'react';
|
|
4
|
+
import { ActivityIndicator, Text, View } from 'react-native';
|
|
5
|
+
import { ButtonRoot as ButtonRootPrimitive, Slot, dataAttributes, mergeDataAttributes } from '@cdx-ui/primitives';
|
|
6
|
+
import { cn, flattenChildren, ParentContext, useParentContext, useStyleContext } from '@cdx-ui/utils';
|
|
7
7
|
import { Icon } from '../Icon';
|
|
8
|
-
import {
|
|
8
|
+
import { positionToDataIcon } from '../../utils/positionToDataIcon';
|
|
9
|
+
import { buttonGroupVariants, buttonIconVariants, buttonRootVariants, buttonSpinnerColorVariants, buttonSpinnerVariants, buttonTextVariants } from './styles';
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
11
|
const SCOPE = 'BUTTON';
|
|
11
|
-
const Root = withStyleContext(Pressable, SCOPE);
|
|
12
12
|
const useButtonStyleContext = () => useStyleContext(SCOPE);
|
|
13
|
-
const ButtonPrimitive = createButton({
|
|
14
|
-
Root,
|
|
15
|
-
Text,
|
|
16
|
-
Group: View,
|
|
17
|
-
Spinner: ActivityIndicator,
|
|
18
|
-
Icon: View
|
|
19
|
-
});
|
|
20
13
|
|
|
21
14
|
// =============================================================================
|
|
22
15
|
// STYLED ROOT COMPONENT
|
|
@@ -49,27 +42,38 @@ const ButtonRoot = /*#__PURE__*/forwardRef(({
|
|
|
49
42
|
size,
|
|
50
43
|
fullWidth
|
|
51
44
|
}), className);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
context: {
|
|
45
|
+
const parent = useParentContext();
|
|
46
|
+
const ctx = useMemo(() => ({
|
|
47
|
+
...parent,
|
|
48
|
+
[SCOPE]: {
|
|
57
49
|
variant,
|
|
58
50
|
color,
|
|
59
51
|
size,
|
|
60
52
|
fullWidth
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
}
|
|
54
|
+
}), [parent, variant, color, size, fullWidth]);
|
|
55
|
+
return /*#__PURE__*/_jsx(ParentContext.Provider, {
|
|
56
|
+
value: ctx,
|
|
57
|
+
children: /*#__PURE__*/_jsx(ButtonRootPrimitive, {
|
|
58
|
+
ref: ref,
|
|
59
|
+
className: computedClassName,
|
|
60
|
+
style: style,
|
|
61
|
+
...props,
|
|
62
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
63
|
+
slot: 'button'
|
|
64
|
+
})),
|
|
65
|
+
children: children
|
|
66
|
+
})
|
|
64
67
|
});
|
|
65
68
|
});
|
|
66
69
|
ButtonRoot.displayName = 'Button';
|
|
67
70
|
|
|
68
71
|
// =============================================================================
|
|
69
|
-
// STYLED
|
|
72
|
+
// STYLED LABEL COMPONENT
|
|
70
73
|
// =============================================================================
|
|
71
74
|
|
|
72
75
|
const ButtonLabel = /*#__PURE__*/forwardRef(({
|
|
76
|
+
asChild,
|
|
73
77
|
className,
|
|
74
78
|
children,
|
|
75
79
|
style,
|
|
@@ -85,46 +89,110 @@ const ButtonLabel = /*#__PURE__*/forwardRef(({
|
|
|
85
89
|
color,
|
|
86
90
|
size
|
|
87
91
|
}), className);
|
|
88
|
-
|
|
92
|
+
const Comp = asChild ? Slot : Text;
|
|
93
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
89
94
|
ref: ref,
|
|
90
95
|
className: computedClassName,
|
|
91
96
|
style: style,
|
|
92
97
|
...props,
|
|
98
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
99
|
+
slot: 'button-label'
|
|
100
|
+
})),
|
|
93
101
|
children: children
|
|
94
102
|
});
|
|
95
103
|
});
|
|
96
104
|
ButtonLabel.displayName = 'Button.Label';
|
|
97
105
|
|
|
106
|
+
// =============================================================================
|
|
107
|
+
// STYLED GROUP COMPONENT
|
|
108
|
+
// =============================================================================
|
|
109
|
+
|
|
98
110
|
// TODO: Use ButtonGroupVariantProps
|
|
99
111
|
|
|
100
112
|
const ButtonGroup = /*#__PURE__*/forwardRef(({
|
|
113
|
+
asChild,
|
|
101
114
|
className,
|
|
102
115
|
children,
|
|
103
116
|
style,
|
|
104
117
|
flexDirection = 'row',
|
|
105
118
|
isAttached,
|
|
119
|
+
isDisabled,
|
|
120
|
+
isReversed,
|
|
121
|
+
reversed,
|
|
106
122
|
...props
|
|
107
123
|
}, ref) => {
|
|
124
|
+
const direction = flexDirection.includes('reverse') ? flexDirection === 'column-reverse' ? 'column' : 'row' : flexDirection;
|
|
125
|
+
let childrenArray = React.Children.toArray(flattenChildren(children));
|
|
126
|
+
childrenArray = isReversed || reversed ? [...childrenArray].reverse() : childrenArray;
|
|
127
|
+
const computedChildren = childrenArray.map((child, index) => {
|
|
128
|
+
if (typeof child === 'string' || typeof child === 'number') {
|
|
129
|
+
return child;
|
|
130
|
+
}
|
|
131
|
+
const attachedStyles = {};
|
|
132
|
+
if (index === 0) {
|
|
133
|
+
if (direction === 'column') {
|
|
134
|
+
attachedStyles.borderBottomLeftRadius = 0;
|
|
135
|
+
attachedStyles.borderBottomRightRadius = 0;
|
|
136
|
+
} else {
|
|
137
|
+
attachedStyles.borderTopRightRadius = 0;
|
|
138
|
+
attachedStyles.borderBottomRightRadius = 0;
|
|
139
|
+
}
|
|
140
|
+
} else if (index === childrenArray.length - 1) {
|
|
141
|
+
if (direction === 'column') {
|
|
142
|
+
attachedStyles.borderTopLeftRadius = 0;
|
|
143
|
+
attachedStyles.borderTopRightRadius = 0;
|
|
144
|
+
} else {
|
|
145
|
+
attachedStyles.borderTopLeftRadius = 0;
|
|
146
|
+
attachedStyles.borderBottomLeftRadius = 0;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
attachedStyles.borderRadius = 0;
|
|
150
|
+
}
|
|
151
|
+
const childProps = {
|
|
152
|
+
isDisabled,
|
|
153
|
+
...child.props,
|
|
154
|
+
style: {
|
|
155
|
+
...(isAttached ? attachedStyles : {}),
|
|
156
|
+
...child.props.style
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
160
|
+
children: /*#__PURE__*/React.cloneElement(child, childProps)
|
|
161
|
+
}, child.key ?? `spaced-child-${index.toString()}`);
|
|
162
|
+
});
|
|
108
163
|
const groupClassName = cn(buttonGroupVariants({
|
|
109
164
|
flexDirection,
|
|
110
165
|
isAttached: !!isAttached
|
|
111
166
|
}), className);
|
|
112
|
-
|
|
167
|
+
const Comp = asChild ? Slot : View;
|
|
168
|
+
const gapProp = isAttached ? {
|
|
169
|
+
gap: 0
|
|
170
|
+
} : {};
|
|
171
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
113
172
|
ref: ref,
|
|
114
173
|
className: groupClassName,
|
|
115
174
|
style: [{
|
|
116
175
|
flexDirection
|
|
117
|
-
}, style],
|
|
118
|
-
isAttached: isAttached,
|
|
176
|
+
}, style, gapProp],
|
|
119
177
|
...props,
|
|
120
|
-
|
|
178
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
179
|
+
slot: 'button-group'
|
|
180
|
+
})),
|
|
181
|
+
children: computedChildren
|
|
121
182
|
});
|
|
122
183
|
});
|
|
123
184
|
ButtonGroup.displayName = 'Button.Group';
|
|
185
|
+
|
|
186
|
+
// =============================================================================
|
|
187
|
+
// STYLED ICON COMPONENT
|
|
188
|
+
// =============================================================================
|
|
189
|
+
|
|
124
190
|
const ButtonIcon = ({
|
|
191
|
+
asChild,
|
|
125
192
|
className,
|
|
126
193
|
style,
|
|
127
194
|
as,
|
|
195
|
+
position,
|
|
128
196
|
...props
|
|
129
197
|
}) => {
|
|
130
198
|
const {
|
|
@@ -137,34 +205,64 @@ const ButtonIcon = ({
|
|
|
137
205
|
color,
|
|
138
206
|
size
|
|
139
207
|
}), className);
|
|
208
|
+
if (asChild) {
|
|
209
|
+
return /*#__PURE__*/_jsx(Slot, {
|
|
210
|
+
className: computedClassName,
|
|
211
|
+
style: style,
|
|
212
|
+
...props,
|
|
213
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
214
|
+
slot: 'button-icon'
|
|
215
|
+
}), positionToDataIcon(position))
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
if (!as) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
140
221
|
return /*#__PURE__*/_jsx(Icon, {
|
|
141
222
|
as: as,
|
|
142
223
|
className: computedClassName,
|
|
143
224
|
style: style,
|
|
144
|
-
...props
|
|
225
|
+
...props,
|
|
226
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
227
|
+
slot: 'button-icon'
|
|
228
|
+
}), positionToDataIcon(position))
|
|
145
229
|
});
|
|
146
230
|
};
|
|
147
231
|
ButtonIcon.displayName = 'Button.Icon';
|
|
232
|
+
|
|
233
|
+
// =============================================================================
|
|
234
|
+
// STYLED SPINNER COMPONENT
|
|
235
|
+
// =============================================================================
|
|
236
|
+
|
|
148
237
|
const ButtonSpinner = /*#__PURE__*/forwardRef(({
|
|
238
|
+
asChild,
|
|
149
239
|
className,
|
|
150
240
|
colorClassName,
|
|
151
241
|
style,
|
|
242
|
+
position,
|
|
243
|
+
accessibilityLabel = 'Loading',
|
|
152
244
|
...props
|
|
153
245
|
}, ref) => {
|
|
154
246
|
const {
|
|
155
247
|
variant,
|
|
156
248
|
color
|
|
157
249
|
} = useButtonStyleContext();
|
|
158
|
-
const
|
|
250
|
+
const computedClassName = cn(buttonSpinnerVariants(), className);
|
|
251
|
+
const computedColorClassName = cn(buttonSpinnerColorVariants({
|
|
159
252
|
variant,
|
|
160
253
|
color
|
|
161
254
|
}), colorClassName);
|
|
162
|
-
|
|
255
|
+
const Comp = asChild ? Slot : ActivityIndicator;
|
|
256
|
+
return /*#__PURE__*/_jsx(Comp, {
|
|
163
257
|
ref: ref,
|
|
164
|
-
className:
|
|
258
|
+
className: computedClassName,
|
|
165
259
|
colorClassName: computedColorClassName,
|
|
166
260
|
style: style,
|
|
167
|
-
|
|
261
|
+
accessibilityLabel: accessibilityLabel,
|
|
262
|
+
...props,
|
|
263
|
+
...mergeDataAttributes(props, dataAttributes({
|
|
264
|
+
slot: 'button-spinner'
|
|
265
|
+
}), positionToDataIcon(position))
|
|
168
266
|
});
|
|
169
267
|
});
|
|
170
268
|
ButtonSpinner.displayName = 'Button.Spinner';
|