@cdx-ui/components 0.3.6 → 0.3.8
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/docs/components/content.md +2 -0
- package/docs/components/country-flag/content.md +232 -0
- package/docs/components/currency-flag/content.md +202 -0
- package/docs/components/currency-input/content.md +175 -56
- package/docs/components/data-grid/content.md +3 -1
- package/docs/components/icon/content.md +1 -1
- package/docs/components/input/content.md +1 -0
- package/docs/components/progress-bar/content.md +164 -3
- package/docs/components/select/content.md +1 -0
- package/docs/foundations/expressions/icons/content.md +3 -2
- package/docs/getting-started/developers/content.md +1 -1
- package/docs/getting-started/developers/styling/content.md +2 -2
- package/docs/llms.txt +5 -0
- package/docs/patterns/insights/content.md +70 -1
- package/docs/resources/content.md +1 -0
- package/docs/resources/release-notes/0.3.6/content.md +29 -0
- package/docs/resources/release-notes/0.3.7/content.md +27 -0
- package/docs/resources/release-notes/content.md +2 -0
- package/docs/resources/skills/content.md +66 -0
- package/lib/commonjs/components/BarChart/index.js +5 -12
- package/lib/commonjs/components/BarChart/index.js.map +1 -1
- package/lib/commonjs/components/CountryFlag/index.js +56 -0
- package/lib/commonjs/components/CountryFlag/index.js.map +1 -0
- package/lib/commonjs/components/CurrencyFlag/index.js +77 -0
- package/lib/commonjs/components/CurrencyFlag/index.js.map +1 -0
- package/lib/commonjs/components/CurrencyInput/index.js +3 -1
- package/lib/commonjs/components/CurrencyInput/index.js.map +1 -1
- package/lib/commonjs/components/CurrencyInput/styles.js +23 -7
- package/lib/commonjs/components/CurrencyInput/styles.js.map +1 -1
- package/lib/commonjs/components/Input/index.js.map +1 -1
- package/lib/commonjs/components/LineChart/index.js +3 -6
- package/lib/commonjs/components/LineChart/index.js.map +1 -1
- package/lib/commonjs/components/ProgressBar/index.js +44 -12
- package/lib/commonjs/components/ProgressBar/index.js.map +1 -1
- package/lib/commonjs/components/ProgressBar/styles.js +31 -2
- package/lib/commonjs/components/ProgressBar/styles.js.map +1 -1
- package/lib/commonjs/components/Select/index.js.map +1 -1
- package/lib/commonjs/components/chart/hiddenSvgProps.js +23 -0
- package/lib/commonjs/components/chart/hiddenSvgProps.js.map +1 -0
- package/lib/commonjs/components/index.js +24 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/figma/Accordion.figma.js +2 -2
- package/lib/commonjs/figma/Accordion.figma.js.map +1 -1
- package/lib/commonjs/figma/Alert.figma.js +7 -7
- package/lib/commonjs/figma/Alert.figma.js.map +1 -1
- package/lib/commonjs/figma/Badge.Indicator.figma.js +6 -5
- package/lib/commonjs/figma/Badge.Indicator.figma.js.map +1 -1
- package/lib/commonjs/figma/Badge.figma.js +22 -22
- package/lib/commonjs/figma/Badge.figma.js.map +1 -1
- package/lib/commonjs/figma/Button.figma.js +5 -2
- package/lib/commonjs/figma/Button.figma.js.map +1 -1
- package/lib/commonjs/figma/CLAUDE.md +1 -0
- package/lib/commonjs/figma/Card.Header.figma.js +8 -4
- package/lib/commonjs/figma/Card.Header.figma.js.map +1 -1
- package/lib/commonjs/figma/Card.figma.js +2 -1
- package/lib/commonjs/figma/Card.figma.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/figma/CurrencyInput.figma.js +1 -1
- package/lib/commonjs/figma/CurrencyInput.figma.js.map +1 -1
- package/lib/commonjs/figma/Dialog.figma.js +5 -2
- package/lib/commonjs/figma/Dialog.figma.js.map +1 -1
- package/lib/commonjs/figma/Divider.figma.js +1 -1
- package/lib/commonjs/figma/Divider.figma.js.map +1 -1
- package/lib/commonjs/figma/Drawer.figma.js +3 -3
- package/lib/commonjs/figma/Drawer.figma.js.map +1 -1
- package/lib/commonjs/figma/IconButton.figma.js +10 -4
- package/lib/commonjs/figma/IconButton.figma.js.map +1 -1
- package/lib/commonjs/figma/Input.figma.js +2 -1
- package/lib/commonjs/figma/Input.figma.js.map +1 -1
- package/lib/commonjs/figma/Insight.figma.js +3 -3
- package/lib/commonjs/figma/Insight.figma.js.map +1 -1
- package/lib/commonjs/figma/ProgressBar.figma.js +11 -2
- package/lib/commonjs/figma/ProgressBar.figma.js.map +1 -1
- package/lib/commonjs/figma/ProgressSegmented.figma.js +9 -1
- package/lib/commonjs/figma/ProgressSegmented.figma.js.map +1 -1
- package/lib/commonjs/figma/Select.figma.js +2 -1
- package/lib/commonjs/figma/Select.figma.js.map +1 -1
- package/lib/commonjs/figma/SystemAlert.figma.js +2 -3
- package/lib/commonjs/figma/SystemAlert.figma.js.map +1 -1
- package/lib/commonjs/styles.css +0 -1
- package/lib/module/components/BarChart/index.js +5 -12
- package/lib/module/components/BarChart/index.js.map +1 -1
- package/lib/module/components/CountryFlag/index.js +52 -0
- package/lib/module/components/CountryFlag/index.js.map +1 -0
- package/lib/module/components/CurrencyFlag/index.js +72 -0
- package/lib/module/components/CurrencyFlag/index.js.map +1 -0
- package/lib/module/components/CurrencyInput/index.js +3 -1
- package/lib/module/components/CurrencyInput/index.js.map +1 -1
- package/lib/module/components/CurrencyInput/styles.js +23 -7
- package/lib/module/components/CurrencyInput/styles.js.map +1 -1
- package/lib/module/components/Input/index.js.map +1 -1
- package/lib/module/components/LineChart/index.js +3 -6
- package/lib/module/components/LineChart/index.js.map +1 -1
- package/lib/module/components/ProgressBar/index.js +47 -15
- package/lib/module/components/ProgressBar/index.js.map +1 -1
- package/lib/module/components/ProgressBar/styles.js +31 -2
- package/lib/module/components/ProgressBar/styles.js.map +1 -1
- package/lib/module/components/Select/index.js.map +1 -1
- package/lib/module/components/chart/hiddenSvgProps.js +20 -0
- package/lib/module/components/chart/hiddenSvgProps.js.map +1 -0
- package/lib/module/components/index.js +2 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/figma/Accordion.figma.js +2 -2
- package/lib/module/figma/Accordion.figma.js.map +1 -1
- package/lib/module/figma/Alert.figma.js +7 -7
- package/lib/module/figma/Alert.figma.js.map +1 -1
- package/lib/module/figma/Badge.Indicator.figma.js +6 -5
- package/lib/module/figma/Badge.Indicator.figma.js.map +1 -1
- package/lib/module/figma/Badge.figma.js +22 -22
- package/lib/module/figma/Badge.figma.js.map +1 -1
- package/lib/module/figma/Button.figma.js +5 -2
- package/lib/module/figma/Button.figma.js.map +1 -1
- package/lib/module/figma/CLAUDE.md +1 -0
- package/lib/module/figma/Card.Header.figma.js +8 -4
- package/lib/module/figma/Card.Header.figma.js.map +1 -1
- package/lib/module/figma/Card.figma.js +2 -1
- package/lib/module/figma/Card.figma.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/figma/CurrencyInput.figma.js +1 -1
- package/lib/module/figma/CurrencyInput.figma.js.map +1 -1
- package/lib/module/figma/Dialog.figma.js +5 -2
- package/lib/module/figma/Dialog.figma.js.map +1 -1
- package/lib/module/figma/Divider.figma.js +1 -1
- package/lib/module/figma/Divider.figma.js.map +1 -1
- package/lib/module/figma/Drawer.figma.js +3 -3
- package/lib/module/figma/Drawer.figma.js.map +1 -1
- package/lib/module/figma/IconButton.figma.js +10 -4
- package/lib/module/figma/IconButton.figma.js.map +1 -1
- package/lib/module/figma/Input.figma.js +2 -1
- package/lib/module/figma/Input.figma.js.map +1 -1
- package/lib/module/figma/Insight.figma.js +3 -3
- package/lib/module/figma/Insight.figma.js.map +1 -1
- package/lib/module/figma/ProgressBar.figma.js +12 -2
- package/lib/module/figma/ProgressBar.figma.js.map +1 -1
- package/lib/module/figma/ProgressSegmented.figma.js +9 -1
- package/lib/module/figma/ProgressSegmented.figma.js.map +1 -1
- package/lib/module/figma/Select.figma.js +2 -1
- package/lib/module/figma/Select.figma.js.map +1 -1
- package/lib/module/figma/SystemAlert.figma.js +2 -3
- package/lib/module/figma/SystemAlert.figma.js.map +1 -1
- package/lib/module/styles.css +0 -1
- package/lib/typescript/components/BarChart/index.d.ts.map +1 -1
- package/lib/typescript/components/CountryFlag/index.d.ts +40 -0
- package/lib/typescript/components/CountryFlag/index.d.ts.map +1 -0
- package/lib/typescript/components/CurrencyFlag/index.d.ts +47 -0
- package/lib/typescript/components/CurrencyFlag/index.d.ts.map +1 -0
- package/lib/typescript/components/CurrencyInput/index.d.ts.map +1 -1
- package/lib/typescript/components/CurrencyInput/styles.d.ts +6 -1
- package/lib/typescript/components/CurrencyInput/styles.d.ts.map +1 -1
- package/lib/typescript/components/Input/index.d.ts +2 -0
- package/lib/typescript/components/Input/index.d.ts.map +1 -1
- package/lib/typescript/components/LineChart/index.d.ts.map +1 -1
- package/lib/typescript/components/ProgressBar/index.d.ts +16 -1
- package/lib/typescript/components/ProgressBar/index.d.ts.map +1 -1
- package/lib/typescript/components/ProgressBar/styles.d.ts +7 -2
- package/lib/typescript/components/ProgressBar/styles.d.ts.map +1 -1
- package/lib/typescript/components/Select/index.d.ts +2 -0
- package/lib/typescript/components/Select/index.d.ts.map +1 -1
- package/lib/typescript/components/chart/hiddenSvgProps.d.ts +17 -0
- package/lib/typescript/components/chart/hiddenSvgProps.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/figma/Alert.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Badge.Indicator.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Badge.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Button.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Card.Header.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Card.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Dialog.figma.d.ts.map +1 -1
- package/lib/typescript/figma/IconButton.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Input.figma.d.ts.map +1 -1
- package/lib/typescript/figma/ProgressBar.figma.d.ts.map +1 -1
- package/lib/typescript/figma/ProgressSegmented.figma.d.ts.map +1 -1
- package/lib/typescript/figma/Select.figma.d.ts.map +1 -1
- package/lib/typescript/figma/SystemAlert.figma.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/components/BarChart/index.tsx +5 -12
- package/src/components/CountryFlag/index.tsx +58 -0
- package/src/components/CurrencyFlag/index.tsx +71 -0
- package/src/components/CurrencyInput/index.tsx +2 -1
- package/src/components/CurrencyInput/styles.ts +29 -3
- package/src/components/Input/index.tsx +2 -0
- package/src/components/LineChart/index.tsx +3 -6
- package/src/components/ProgressBar/index.tsx +66 -14
- package/src/components/ProgressBar/styles.ts +35 -4
- package/src/components/Select/index.tsx +2 -0
- package/src/components/chart/hiddenSvgProps.ts +15 -0
- package/src/components/index.ts +2 -0
- package/src/styles.css +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { flags, type FlagCode } from '@cdx-ui/icons/flags';
|
|
2
|
+
import { dataAttributes, mergeDataAttributes } from '@cdx-ui/primitives';
|
|
3
|
+
import { cn } from '@cdx-ui/utils';
|
|
4
|
+
import { Icon, type IconProps } from '../Icon';
|
|
5
|
+
|
|
6
|
+
export interface CurrencyFlagProps extends Omit<IconProps, 'as' | 'filled' | 'color'> {
|
|
7
|
+
/** ISO 4217 alphabetic currency code, such as `USD` or `EUR`. */
|
|
8
|
+
code: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns the flag code for the country or union that issues an ISO 4217 currency.
|
|
13
|
+
*
|
|
14
|
+
* National codes start with the issuer's ISO 3166-1 alpha-2 code (`DKK` → `DK`), so a
|
|
15
|
+
* currency shared by several countries resolves to its issuer. `EUR` resolves to `EU`.
|
|
16
|
+
* `X` codes (`XOF`, `XCD`, `XAU`) have no single issuer and resolve to `undefined`, as
|
|
17
|
+
* do malformed codes.
|
|
18
|
+
*/
|
|
19
|
+
export function currencyFlagCode(code: string): FlagCode | undefined {
|
|
20
|
+
if (!/^[A-Z]{3}$/.test(code)) return undefined;
|
|
21
|
+
if (code === 'EUR') return 'EU';
|
|
22
|
+
// `X` prefixes would otherwise hit user-assigned flags (`XAF` → `XA`, `XCD` → `XC`).
|
|
23
|
+
if (code.startsWith('X')) return undefined;
|
|
24
|
+
const region = code.slice(0, 2);
|
|
25
|
+
return Object.prototype.hasOwnProperty.call(flags, region) ? (region as FlagCode) : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Renders the flag of the country or union that issues an ISO 4217 currency.
|
|
30
|
+
*
|
|
31
|
+
* The flag shows the issuer, not the user's country: `DKK` renders Denmark's flag for
|
|
32
|
+
* accounts in Greenland too. Use `CountryFlag` with a country code when the flag should
|
|
33
|
+
* show where the user is. Codes with no single issuer, such as `XOF` and `XCD`, render
|
|
34
|
+
* nothing and log a warning in development.
|
|
35
|
+
*
|
|
36
|
+
* The flag is drawn through `Icon`, so `className` sizing and `asChild` icon slots
|
|
37
|
+
* apply. Flag artwork keeps its own colors. The flag is decorative unless
|
|
38
|
+
* `accessibilityLabel` is set.
|
|
39
|
+
*
|
|
40
|
+
* @component
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { CurrencyFlag } from '@cdx-ui/components';
|
|
44
|
+
*
|
|
45
|
+
* <CurrencyFlag code="USD" />
|
|
46
|
+
* <CurrencyFlag code="EUR" className="size-6" accessibilityLabel="Euro" />
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param {string} code - ISO 4217 alphabetic currency code.
|
|
50
|
+
* @param {string} className - Utility classes for size and placement, merged after the default `size-5` box.
|
|
51
|
+
* @param {string} accessibilityLabel - When set, the flag is announced as an image with this name.
|
|
52
|
+
* @param {object} style - Style overrides passed through to the icon.
|
|
53
|
+
* @param {string} data-testid - Test identifier forwarded to the rendered icon.
|
|
54
|
+
*/
|
|
55
|
+
export function CurrencyFlag({ code, className, ...props }: CurrencyFlagProps) {
|
|
56
|
+
const flagCode = currencyFlagCode(code);
|
|
57
|
+
if (!flagCode) {
|
|
58
|
+
if (__DEV__) console.warn(`CurrencyFlag: no flag for currency "${code}"`);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return (
|
|
62
|
+
<Icon
|
|
63
|
+
as={flags[flagCode]}
|
|
64
|
+
className={cn('size-5', className)}
|
|
65
|
+
{...props}
|
|
66
|
+
{...mergeDataAttributes(props, dataAttributes({ slot: 'currency-flag' }))}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
CurrencyFlag.displayName = 'CurrencyFlag';
|
|
@@ -62,6 +62,7 @@ export const CurrencyInput = forwardRef<TextInput, CurrencyInputProps>(
|
|
|
62
62
|
currencySymbol = '$',
|
|
63
63
|
variant = 'ghost',
|
|
64
64
|
size = 'default',
|
|
65
|
+
align,
|
|
65
66
|
isDisabled,
|
|
66
67
|
isInvalid,
|
|
67
68
|
isReadOnly,
|
|
@@ -206,7 +207,7 @@ export const CurrencyInput = forwardRef<TextInput, CurrencyInputProps>(
|
|
|
206
207
|
onFocus={handleFocus}
|
|
207
208
|
onBlur={handleBlur}
|
|
208
209
|
className={cn(
|
|
209
|
-
currencyInputFieldVariants({ variant, size }),
|
|
210
|
+
currencyInputFieldVariants({ variant, size, align }),
|
|
210
211
|
isEmpty ? 'text-content-tertiary' : 'text-content-primary',
|
|
211
212
|
)}
|
|
212
213
|
/>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
1
2
|
import { cn, cva } from '@cdx-ui/utils';
|
|
2
3
|
import { DISABLED_CURSOR } from '../../styles/constants';
|
|
3
4
|
import { inputFieldVariants, inputRootVariants } from '../Input/styles';
|
|
@@ -15,6 +16,11 @@ export interface CurrencyInputVariantProps {
|
|
|
15
16
|
* @default 'default'
|
|
16
17
|
*/
|
|
17
18
|
size?: 'default' | 'small';
|
|
19
|
+
/**
|
|
20
|
+
* Horizontal alignment of the amount. Defaults to `center` on `ghost`. On `outline`, the amount
|
|
21
|
+
* stays at the start of the field until `align` is set.
|
|
22
|
+
*/
|
|
23
|
+
align?: 'center' | 'end';
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
const currencyInputGhostRootVariants = cva(
|
|
@@ -37,9 +43,20 @@ const currencyInputGhostRootVariants = cva(
|
|
|
37
43
|
},
|
|
38
44
|
);
|
|
39
45
|
|
|
46
|
+
// TextInput only accepts textAlign left, center, and right. `text-end` is valid CSS, so web
|
|
47
|
+
// uses it, but native ignores it and the amount stays at the start in LTR. Direction
|
|
48
|
+
// variants compile to left/right, matching Table's native text alignment.
|
|
49
|
+
const currencyInputAlignClass = {
|
|
50
|
+
center: 'text-center',
|
|
51
|
+
end: Platform.select({
|
|
52
|
+
web: 'text-end',
|
|
53
|
+
default: 'ltr:text-right rtl:text-left',
|
|
54
|
+
}),
|
|
55
|
+
} as const;
|
|
56
|
+
|
|
40
57
|
const currencyInputGhostFieldVariants = cva(
|
|
41
58
|
[
|
|
42
|
-
'w-full bg-transparent p-0
|
|
59
|
+
'w-full bg-transparent p-0',
|
|
43
60
|
'placeholder:text-content-tertiary',
|
|
44
61
|
'web:outline-none',
|
|
45
62
|
'data-[invalid=true]:text-content-danger',
|
|
@@ -71,8 +88,17 @@ export const currencyInputRootVariants = ({
|
|
|
71
88
|
export const currencyInputFieldVariants = ({
|
|
72
89
|
variant = 'ghost',
|
|
73
90
|
size = 'default',
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
align,
|
|
92
|
+
}: CurrencyInputVariantProps = {}): string => {
|
|
93
|
+
const resolvedAlign = align ?? (variant === 'outline' ? undefined : 'center');
|
|
94
|
+
|
|
95
|
+
return cn(
|
|
96
|
+
variant === 'outline'
|
|
97
|
+
? inputFieldVariants({ size })
|
|
98
|
+
: currencyInputGhostFieldVariants({ size }),
|
|
99
|
+
resolvedAlign ? currencyInputAlignClass[resolvedAlign] : undefined,
|
|
100
|
+
);
|
|
101
|
+
};
|
|
76
102
|
|
|
77
103
|
// Figma keeps the symbol at body-md on every viewport; only the amount grows to 16px on web <600px.
|
|
78
104
|
export const currencyInputPrefixVariants = cva(
|
|
@@ -160,6 +160,8 @@ export interface InputIconProps extends Omit<IconProps, 'children' | 'as' | 'col
|
|
|
160
160
|
* case the consumer's substituted element is rendered instead.
|
|
161
161
|
*/
|
|
162
162
|
as?: IconProps['as'];
|
|
163
|
+
/** The element rendered when `asChild` is set. */
|
|
164
|
+
children?: ReactNode;
|
|
163
165
|
}
|
|
164
166
|
|
|
165
167
|
const InputIcon = ({ asChild, className, style, as, ...props }: InputIconProps) => {
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
type ChartInspectorTarget,
|
|
27
27
|
} from '../chart/ChartInspector';
|
|
28
28
|
import { resolveChartLocaleText, resolveValueFormatter } from '../chart/format';
|
|
29
|
+
import { HIDDEN_SVG_PROPS } from '../chart/hiddenSvgProps';
|
|
29
30
|
import { resolveChartBox } from '../chart/size';
|
|
30
31
|
import type {
|
|
31
32
|
ChartAxis,
|
|
@@ -398,9 +399,7 @@ function LineChartInner<TRow extends object>(
|
|
|
398
399
|
width={axisWidth}
|
|
399
400
|
height={viewportHeight}
|
|
400
401
|
viewBox={`0 0 ${String(axisWidth)} ${String(content.height)}`}
|
|
401
|
-
|
|
402
|
-
accessibilityElementsHidden
|
|
403
|
-
importantForAccessibility="no-hide-descendants"
|
|
402
|
+
{...HIDDEN_SVG_PROPS}
|
|
404
403
|
>
|
|
405
404
|
{ticks}
|
|
406
405
|
</Svg>
|
|
@@ -425,9 +424,7 @@ function LineChartInner<TRow extends object>(
|
|
|
425
424
|
height={viewportHeight}
|
|
426
425
|
viewBox={`0 0 ${String(plotWidth + bleed)} ${String(content.height)}`}
|
|
427
426
|
pointerEvents="none"
|
|
428
|
-
|
|
429
|
-
accessibilityElementsHidden
|
|
430
|
-
importantForAccessibility="no-hide-descendants"
|
|
427
|
+
{...HIDDEN_SVG_PROPS}
|
|
431
428
|
>
|
|
432
429
|
<G transform={`translate(${String(-axisWidth)}, 0)`}>{plot}</G>
|
|
433
430
|
</Svg>
|
|
@@ -1,40 +1,92 @@
|
|
|
1
|
-
import { forwardRef } from 'react';
|
|
1
|
+
import { forwardRef, useMemo } from 'react';
|
|
2
2
|
import { View, type ViewProps } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
ProgressBarRoot,
|
|
5
|
+
ProgressBarIndicator,
|
|
6
|
+
dataAttributes,
|
|
7
|
+
mergeDataAttributes,
|
|
8
|
+
type IProgressProps,
|
|
9
|
+
} from '@cdx-ui/primitives';
|
|
10
|
+
import { cn, ParentContext, useParentContext, useStyleContext } from '@cdx-ui/utils';
|
|
5
11
|
import {
|
|
6
12
|
progressBarIndicatorVariants,
|
|
7
13
|
progressBarTrackVariants,
|
|
14
|
+
type ProgressBarIndicatorVariantProps,
|
|
8
15
|
type ProgressBarTrackVariantProps,
|
|
9
16
|
} from './styles';
|
|
10
17
|
|
|
18
|
+
const SCOPE = 'PROGRESS_BAR';
|
|
19
|
+
|
|
20
|
+
export type ProgressBarSize = NonNullable<ProgressBarTrackVariantProps['size']>;
|
|
21
|
+
export type ProgressBarColor = NonNullable<ProgressBarIndicatorVariantProps['color']>;
|
|
22
|
+
|
|
23
|
+
interface ProgressBarStyleContext {
|
|
24
|
+
size?: ProgressBarSize;
|
|
25
|
+
color?: ProgressBarColor;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const useProgressBarStyleContext = () => useStyleContext(SCOPE) as ProgressBarStyleContext;
|
|
29
|
+
|
|
11
30
|
export interface ProgressBarProps extends IProgressProps, ProgressBarTrackVariantProps {
|
|
31
|
+
/**
|
|
32
|
+
* Track height. Inherited by `ProgressBar.Indicator` via style context.
|
|
33
|
+
* @default 'default'
|
|
34
|
+
*/
|
|
35
|
+
size?: ProgressBarSize;
|
|
36
|
+
/**
|
|
37
|
+
* Indicator fill color. Inherited by `ProgressBar.Indicator` via style context.
|
|
38
|
+
* The track is always `surface-neutral-subtle`.
|
|
39
|
+
* @default 'action'
|
|
40
|
+
*/
|
|
41
|
+
color?: ProgressBarColor;
|
|
42
|
+
/** Additional Uniwind/Tailwind classes, merged after the track's own styles. */
|
|
12
43
|
readonly className?: string;
|
|
13
44
|
}
|
|
14
45
|
|
|
15
46
|
export interface ProgressBarIndicatorProps extends ViewProps {
|
|
47
|
+
/** Additional Uniwind/Tailwind classes, merged after the indicator's own styles. */
|
|
16
48
|
readonly className?: string;
|
|
17
49
|
}
|
|
18
50
|
|
|
19
51
|
const ProgressBarRootComponent = forwardRef<View, ProgressBarProps>(
|
|
20
|
-
({ className, style, ...props }, ref) => {
|
|
21
|
-
const trackClass = cn(progressBarTrackVariants(), className);
|
|
52
|
+
({ className, style, size = 'default', color = 'action', children, ...props }, ref) => {
|
|
53
|
+
const trackClass = cn(progressBarTrackVariants({ size }), className);
|
|
54
|
+
|
|
55
|
+
const parent = useParentContext();
|
|
56
|
+
const ctx = useMemo(() => ({ ...parent, [SCOPE]: { size, color } }), [parent, size, color]);
|
|
22
57
|
|
|
23
|
-
return
|
|
58
|
+
return (
|
|
59
|
+
<ParentContext.Provider value={ctx}>
|
|
60
|
+
<ProgressBarRoot
|
|
61
|
+
ref={ref}
|
|
62
|
+
className={trackClass}
|
|
63
|
+
style={style}
|
|
64
|
+
{...props}
|
|
65
|
+
{...mergeDataAttributes(props, dataAttributes({ slot: 'progress-bar' }))}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</ProgressBarRoot>
|
|
69
|
+
</ParentContext.Provider>
|
|
70
|
+
);
|
|
24
71
|
},
|
|
25
72
|
);
|
|
26
73
|
|
|
27
74
|
ProgressBarRootComponent.displayName = 'ProgressBar';
|
|
28
75
|
|
|
29
76
|
const ProgressBarIndicatorComponent = forwardRef<View, ProgressBarIndicatorProps>(
|
|
30
|
-
({ className, style, ...props }, ref) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
77
|
+
({ className, style, ...props }, ref) => {
|
|
78
|
+
const { color } = useProgressBarStyleContext();
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<ProgressBarIndicator
|
|
82
|
+
ref={ref}
|
|
83
|
+
className={cn(progressBarIndicatorVariants({ color }), className)}
|
|
84
|
+
style={style}
|
|
85
|
+
{...props}
|
|
86
|
+
{...mergeDataAttributes(props, dataAttributes({ slot: 'progress-bar-indicator' }))}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
},
|
|
38
90
|
);
|
|
39
91
|
|
|
40
92
|
ProgressBarIndicatorComponent.displayName = 'ProgressBar.Indicator';
|
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
import { cva, type VariantProps } from '@cdx-ui/utils';
|
|
2
2
|
|
|
3
|
-
export const progressBarTrackVariants = cva(
|
|
4
|
-
'w-full flex-row overflow-hidden rounded-full bg-surface-
|
|
5
|
-
|
|
3
|
+
export const progressBarTrackVariants = cva(
|
|
4
|
+
['w-full flex-row overflow-hidden rounded-full bg-surface-neutral-subtle'],
|
|
5
|
+
{
|
|
6
|
+
variants: {
|
|
7
|
+
size: {
|
|
8
|
+
default: 'h-1.5',
|
|
9
|
+
large: 'h-2',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
defaultVariants: {
|
|
13
|
+
size: 'default',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
);
|
|
6
17
|
|
|
7
|
-
export const progressBarIndicatorVariants = cva(['rounded-full
|
|
18
|
+
export const progressBarIndicatorVariants = cva(['rounded-full'], {
|
|
19
|
+
variants: {
|
|
20
|
+
color: {
|
|
21
|
+
action: 'bg-surface-action-strong',
|
|
22
|
+
danger: 'bg-surface-danger-strong',
|
|
23
|
+
warning: 'bg-surface-warning-strong',
|
|
24
|
+
success: 'bg-surface-success-strong',
|
|
25
|
+
info: 'bg-surface-info-strong',
|
|
26
|
+
'categorical-1': 'bg-chart-categorical-1',
|
|
27
|
+
'categorical-2': 'bg-chart-categorical-2',
|
|
28
|
+
'categorical-3': 'bg-chart-categorical-3',
|
|
29
|
+
'categorical-4': 'bg-chart-categorical-4',
|
|
30
|
+
'categorical-5': 'bg-chart-categorical-5',
|
|
31
|
+
'categorical-6': 'bg-chart-categorical-6',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
defaultVariants: {
|
|
35
|
+
color: 'action',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
8
38
|
|
|
9
39
|
export type ProgressBarTrackVariantProps = VariantProps<typeof progressBarTrackVariants>;
|
|
40
|
+
export type ProgressBarIndicatorVariantProps = VariantProps<typeof progressBarIndicatorVariants>;
|
|
@@ -273,6 +273,8 @@ export interface SelectIconProps extends Omit<IconProps, 'children' | 'as' | 'co
|
|
|
273
273
|
* Omit to apply the symmetric baseline gap.
|
|
274
274
|
*/
|
|
275
275
|
position?: IconSlotPosition;
|
|
276
|
+
/** The element rendered when `asChild` is set. */
|
|
277
|
+
children?: ReactNode;
|
|
276
278
|
}
|
|
277
279
|
|
|
278
280
|
const SelectIcon = ({ asChild, className, style, as, position, ...props }: SelectIconProps) => {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hides a decorative `Svg` from assistive technology. On web, react-native-svg renders a raw
|
|
5
|
+
* `<svg>` without react-native-web's prop filtering, so RN-only accessibility props would reach
|
|
6
|
+
* the DOM as unknown attributes and log React warnings.
|
|
7
|
+
*/
|
|
8
|
+
export const HIDDEN_SVG_PROPS = Platform.select({
|
|
9
|
+
web: { 'aria-hidden': true },
|
|
10
|
+
default: {
|
|
11
|
+
accessible: false,
|
|
12
|
+
accessibilityElementsHidden: true,
|
|
13
|
+
importantForAccessibility: 'no-hide-descendants',
|
|
14
|
+
},
|
|
15
|
+
} as const);
|
package/src/components/index.ts
CHANGED
|
@@ -76,5 +76,7 @@ export { HStack, VStack } from './Stack';
|
|
|
76
76
|
export * from './Heading';
|
|
77
77
|
export * from './Text';
|
|
78
78
|
export * from './Icon';
|
|
79
|
+
export * from './CountryFlag';
|
|
80
|
+
export * from './CurrencyFlag';
|
|
79
81
|
export * from './IconButton';
|
|
80
82
|
export * from './QuickActionButton';
|