@cdx-ui/primitives 0.0.1-alpha.34 → 0.0.1-alpha.36
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/{form-control/createFormError.js → field/createFieldError.js} +4 -4
- package/lib/commonjs/field/createFieldError.js.map +1 -0
- package/lib/commonjs/{form-control/createFormErrorIcon.js → field/createFieldErrorIcon.js} +4 -4
- package/lib/commonjs/field/createFieldErrorIcon.js.map +1 -0
- package/lib/commonjs/{form-control/createFormErrorText.js → field/createFieldErrorText.js} +4 -4
- package/lib/commonjs/field/createFieldErrorText.js.map +1 -0
- package/lib/commonjs/{form-control/createFormHelper.js → field/createFieldHelper.js} +4 -4
- package/lib/commonjs/field/createFieldHelper.js.map +1 -0
- package/lib/commonjs/{form-control/createFormHelperText.js → field/createFieldHelperText.js} +4 -4
- package/lib/commonjs/field/createFieldHelperText.js.map +1 -0
- package/lib/commonjs/{form-control/createFormLabel.js → field/createFieldLabel.js} +4 -6
- package/lib/commonjs/field/createFieldLabel.js.map +1 -0
- package/lib/commonjs/{form-control/createFormField.js → field/createFieldRoot.js} +4 -4
- package/lib/commonjs/field/createFieldRoot.js.map +1 -0
- package/lib/commonjs/field/index.js +46 -0
- package/lib/commonjs/field/index.js.map +1 -0
- package/lib/commonjs/{form-control → field}/types.js.map +1 -1
- package/lib/commonjs/form/createFormRoot.js.map +1 -0
- package/lib/commonjs/form/index.js +15 -0
- package/lib/commonjs/form/index.js.map +1 -0
- package/lib/commonjs/form/types.js +6 -0
- package/lib/{module/form-control → commonjs/form}/types.js.map +1 -1
- package/lib/commonjs/index.js +28 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/progress/context.js +11 -0
- package/lib/commonjs/progress/context.js.map +1 -0
- package/lib/commonjs/progress/createProgressIndicator.js +42 -0
- package/lib/commonjs/progress/createProgressIndicator.js.map +1 -0
- package/lib/commonjs/progress/createProgressRoot.js +96 -0
- package/lib/commonjs/progress/createProgressRoot.js.map +1 -0
- package/lib/commonjs/progress/index.js +25 -0
- package/lib/commonjs/progress/index.js.map +1 -0
- package/lib/commonjs/progress/types.js +6 -0
- package/lib/commonjs/progress/types.js.map +1 -0
- package/lib/module/{form-control/createFormError.js → field/createFieldError.js} +2 -2
- package/lib/module/field/createFieldError.js.map +1 -0
- package/lib/module/{form-control/createFormErrorIcon.js → field/createFieldErrorIcon.js} +2 -2
- package/lib/module/field/createFieldErrorIcon.js.map +1 -0
- package/lib/module/{form-control/createFormErrorText.js → field/createFieldErrorText.js} +2 -2
- package/lib/module/field/createFieldErrorText.js.map +1 -0
- package/lib/module/{form-control/createFormHelper.js → field/createFieldHelper.js} +2 -2
- package/lib/module/field/createFieldHelper.js.map +1 -0
- package/lib/module/{form-control/createFormHelperText.js → field/createFieldHelperText.js} +2 -2
- package/lib/module/field/createFieldHelperText.js.map +1 -0
- package/lib/module/{form-control/createFormLabel.js → field/createFieldLabel.js} +2 -4
- package/lib/module/field/createFieldLabel.js.map +1 -0
- package/lib/module/{form-control/createFormField.js → field/createFieldRoot.js} +2 -2
- package/lib/module/field/createFieldRoot.js.map +1 -0
- package/lib/module/field/index.js +42 -0
- package/lib/module/field/index.js.map +1 -0
- package/lib/module/field/types.js.map +1 -0
- package/lib/module/form/createFormRoot.js.map +1 -0
- package/lib/module/form/index.js +11 -0
- package/lib/module/form/index.js.map +1 -0
- package/lib/module/form/types.js +4 -0
- package/lib/module/form/types.js.map +1 -0
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/progress/context.js +5 -0
- package/lib/module/progress/context.js.map +1 -0
- package/lib/module/progress/createProgressIndicator.js +37 -0
- package/lib/module/progress/createProgressIndicator.js.map +1 -0
- package/lib/module/progress/createProgressRoot.js +91 -0
- package/lib/module/progress/createProgressRoot.js.map +1 -0
- package/lib/module/progress/index.js +15 -0
- package/lib/module/progress/index.js.map +1 -0
- package/lib/module/progress/types.js +4 -0
- package/lib/module/progress/types.js.map +1 -0
- package/lib/typescript/field/createFieldError.d.ts +5 -0
- package/lib/typescript/field/createFieldError.d.ts.map +1 -0
- package/lib/typescript/field/createFieldErrorIcon.d.ts +5 -0
- package/lib/typescript/field/createFieldErrorIcon.d.ts.map +1 -0
- package/lib/typescript/field/createFieldErrorText.d.ts +5 -0
- package/lib/typescript/field/createFieldErrorText.d.ts.map +1 -0
- package/lib/typescript/field/createFieldHelper.d.ts +5 -0
- package/lib/typescript/field/createFieldHelper.d.ts.map +1 -0
- package/lib/typescript/field/createFieldHelperText.d.ts +5 -0
- package/lib/typescript/field/createFieldHelperText.d.ts.map +1 -0
- package/lib/typescript/field/createFieldLabel.d.ts +6 -0
- package/lib/typescript/field/createFieldLabel.d.ts.map +1 -0
- package/lib/typescript/field/createFieldRoot.d.ts +6 -0
- package/lib/typescript/field/createFieldRoot.d.ts.map +1 -0
- package/lib/typescript/field/index.d.ts +13 -0
- package/lib/typescript/field/index.d.ts.map +1 -0
- package/lib/typescript/{form-control → field}/types.d.ts +14 -24
- package/lib/typescript/field/types.d.ts.map +1 -0
- package/lib/typescript/form/createFormRoot.d.ts +4 -0
- package/lib/typescript/form/createFormRoot.d.ts.map +1 -0
- package/lib/typescript/form/index.d.ts +6 -0
- package/lib/typescript/form/index.d.ts.map +1 -0
- package/lib/typescript/form/types.d.ts +14 -0
- package/lib/typescript/form/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/progress/context.d.ts +13 -0
- package/lib/typescript/progress/context.d.ts.map +1 -0
- package/lib/typescript/progress/createProgressIndicator.d.ts +3 -0
- package/lib/typescript/progress/createProgressIndicator.d.ts.map +1 -0
- package/lib/typescript/progress/createProgressRoot.d.ts +4 -0
- package/lib/typescript/progress/createProgressRoot.d.ts.map +1 -0
- package/lib/typescript/progress/index.d.ts +10 -0
- package/lib/typescript/progress/index.d.ts.map +1 -0
- package/lib/typescript/progress/types.d.ts +25 -0
- package/lib/typescript/progress/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/{form-control/createFormError.tsx → field/createFieldError.tsx} +1 -1
- package/src/{form-control/createFormErrorIcon.tsx → field/createFieldErrorIcon.tsx} +1 -1
- package/src/{form-control/createFormErrorText.tsx → field/createFieldErrorText.tsx} +1 -1
- package/src/{form-control/createFormHelper.tsx → field/createFieldHelper.tsx} +1 -1
- package/src/{form-control/createFormHelperText.tsx → field/createFieldHelperText.tsx} +1 -1
- package/src/{form-control/createFormLabel.tsx → field/createFieldLabel.tsx} +3 -3
- package/src/{form-control/createFormField.tsx → field/createFieldRoot.tsx} +3 -3
- package/src/field/index.tsx +68 -0
- package/src/{form-control → field}/types.tsx +28 -42
- package/src/{form-control → form}/createFormRoot.tsx +3 -3
- package/src/form/index.tsx +12 -0
- package/src/form/types.tsx +16 -0
- package/src/index.ts +3 -1
- package/src/progress/context.tsx +13 -0
- package/src/progress/createProgressIndicator.tsx +35 -0
- package/src/progress/createProgressRoot.tsx +109 -0
- package/src/progress/index.ts +28 -0
- package/src/progress/types.ts +37 -0
- package/lib/commonjs/form-control/createFormError.js.map +0 -1
- package/lib/commonjs/form-control/createFormErrorIcon.js.map +0 -1
- package/lib/commonjs/form-control/createFormErrorText.js.map +0 -1
- package/lib/commonjs/form-control/createFormField.js.map +0 -1
- package/lib/commonjs/form-control/createFormHelper.js.map +0 -1
- package/lib/commonjs/form-control/createFormHelperText.js.map +0 -1
- package/lib/commonjs/form-control/createFormLabel.js.map +0 -1
- package/lib/commonjs/form-control/createFormRoot.js.map +0 -1
- package/lib/commonjs/form-control/index.js +0 -53
- package/lib/commonjs/form-control/index.js.map +0 -1
- package/lib/module/form-control/createFormError.js.map +0 -1
- package/lib/module/form-control/createFormErrorIcon.js.map +0 -1
- package/lib/module/form-control/createFormErrorText.js.map +0 -1
- package/lib/module/form-control/createFormField.js.map +0 -1
- package/lib/module/form-control/createFormHelper.js.map +0 -1
- package/lib/module/form-control/createFormHelperText.js.map +0 -1
- package/lib/module/form-control/createFormLabel.js.map +0 -1
- package/lib/module/form-control/createFormRoot.js.map +0 -1
- package/lib/module/form-control/index.js +0 -49
- package/lib/module/form-control/index.js.map +0 -1
- package/lib/typescript/form-control/createFormError.d.ts +0 -5
- package/lib/typescript/form-control/createFormError.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormErrorIcon.d.ts +0 -5
- package/lib/typescript/form-control/createFormErrorIcon.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormErrorText.d.ts +0 -5
- package/lib/typescript/form-control/createFormErrorText.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormField.d.ts +0 -6
- package/lib/typescript/form-control/createFormField.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormHelper.d.ts +0 -5
- package/lib/typescript/form-control/createFormHelper.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormHelperText.d.ts +0 -5
- package/lib/typescript/form-control/createFormHelperText.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormLabel.d.ts +0 -8
- package/lib/typescript/form-control/createFormLabel.d.ts.map +0 -1
- package/lib/typescript/form-control/createFormRoot.d.ts +0 -6
- package/lib/typescript/form-control/createFormRoot.d.ts.map +0 -1
- package/lib/typescript/form-control/index.d.ts +0 -14
- package/lib/typescript/form-control/index.d.ts.map +0 -1
- package/lib/typescript/form-control/types.d.ts.map +0 -1
- package/src/form-control/index.tsx +0 -71
- /package/lib/commonjs/{form-control → field}/types.js +0 -0
- /package/lib/commonjs/{form-control → form}/createFormRoot.js +0 -0
- /package/lib/module/{form-control → field}/types.js +0 -0
- /package/lib/module/{form-control → form}/createFormRoot.js +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the Form container (`<form>` on web, `<View>` on RN).
|
|
4
|
+
* Does NOT provide field-level context — use `Form.Field` for that.
|
|
5
|
+
*
|
|
6
|
+
* Web-only submit props (`onSubmit`, `action`, `method`) belong in the
|
|
7
|
+
* platform-specific base component (`FormRoot.web.tsx`), not here.
|
|
8
|
+
*/
|
|
9
|
+
export interface IFormRootProps {
|
|
10
|
+
}
|
|
11
|
+
export type IFormComponentType<Root> = React.ForwardRefExoticComponent<InnerForwardRefExoticComponent<Root> & IFormRootProps>;
|
|
12
|
+
type InnerForwardRefExoticComponent<T> = React.PropsWithoutRef<T> & React.RefAttributes<unknown>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/form/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,MAAM,kBAAkB,CAAC,IAAI,IAAI,KAAK,CAAC,yBAAyB,CACpE,8BAA8B,CAAC,IAAI,CAAC,GAAG,cAAc,CACtD,CAAC;AAEF,KAAK,8BAA8B,CAAC,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -2,12 +2,14 @@ export * from './avatar';
|
|
|
2
2
|
export * from './button';
|
|
3
3
|
export * from './checkbox';
|
|
4
4
|
export * from './dialog';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './field';
|
|
6
|
+
export * from './form';
|
|
6
7
|
export * from './input';
|
|
7
8
|
export * from './link';
|
|
8
9
|
export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
|
|
9
10
|
export * from './select';
|
|
10
11
|
export * from './switch';
|
|
12
|
+
export * from './progress';
|
|
11
13
|
export type { InteractionState } from './types';
|
|
12
14
|
export { dataAttributes } from './utils/dataAttributes';
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,KAAK,UAAU,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACnE,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProgressDataState } from './types';
|
|
2
|
+
export interface ProgressContextValue {
|
|
3
|
+
/** Clamped value in [0, max], or null when indeterminate */
|
|
4
|
+
readonly value: number | null;
|
|
5
|
+
readonly max: number;
|
|
6
|
+
readonly percent: number;
|
|
7
|
+
readonly state: ProgressDataState;
|
|
8
|
+
}
|
|
9
|
+
export declare const ProgressProvider: import("react").FunctionComponent<{
|
|
10
|
+
children: import("react").ReactNode;
|
|
11
|
+
value: ProgressContextValue;
|
|
12
|
+
}>, useProgressContext: () => ProgressContextValue;
|
|
13
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/progress/context.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;CACnC;AAED,eAAO,MAAO,gBAAgB;;;IAAE,kBAAkB,4BACM,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export declare const createProgressIndicator: <T, R = unknown>(BaseIndicator: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<T>> & React.RefAttributes<R>>;
|
|
3
|
+
//# sourceMappingURL=createProgressIndicator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProgressIndicator.d.ts","sourceRoot":"","sources":["../../../src/progress/createProgressIndicator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,eAAO,MAAM,uBAAuB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,eAAe,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,8GA0BzF,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { InterfaceProgressProps } from './types';
|
|
3
|
+
export declare const createProgressRoot: <T, R = unknown>(BaseRoot: React.ComponentType<T>) => React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<T> & InterfaceProgressProps> & React.RefAttributes<R>>;
|
|
4
|
+
//# sourceMappingURL=createProgressRoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createProgressRoot.d.ts","sourceRoot":"","sources":["../../../src/progress/createProgressRoot.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,sBAAsB,EAAqB,MAAM,SAAS,CAAC;AA8BzE,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,UAAU,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,uIA0E/E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { IProgressComponentType } from './types';
|
|
3
|
+
export type { IProgressProps, IProgressComponentType, ProgressDataState } from './types';
|
|
4
|
+
export type { ProgressContextValue } from './context';
|
|
5
|
+
export { useProgressContext } from './context';
|
|
6
|
+
export declare function createProgress<RootProps, IndicatorProps, RootRef = unknown, IndicatorRef = unknown>(components: {
|
|
7
|
+
Root: React.ComponentType<RootProps>;
|
|
8
|
+
Indicator: React.ComponentType<IndicatorProps>;
|
|
9
|
+
}): IProgressComponentType<RootProps, IndicatorProps, RootRef, IndicatorRef>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/progress/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACzF,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,wBAAgB,cAAc,CAC5B,SAAS,EACT,cAAc,EACd,OAAO,GAAG,OAAO,EACjB,YAAY,GAAG,OAAO,EACtB,UAAU,EAAE;IACZ,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;CAChD,GASO,sBAAsB,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,CAAC,CAC/E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ForwardRefExoticComponent, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
export type ProgressDataState = 'complete' | 'indeterminate' | 'loading';
|
|
4
|
+
export interface InterfaceProgressProps extends Omit<ViewProps, 'children'> {
|
|
5
|
+
/**
|
|
6
|
+
* Current value in the range [0, max], or `null` for indeterminate progress.
|
|
7
|
+
* Omit or use a number for determinate progress; default is `0`.
|
|
8
|
+
*/
|
|
9
|
+
readonly value?: number | null;
|
|
10
|
+
/**
|
|
11
|
+
* Maximum value (minimum is always 0).
|
|
12
|
+
* @default 100
|
|
13
|
+
*/
|
|
14
|
+
readonly max?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Optional label for `accessibilityValue.text` when determinate.
|
|
17
|
+
*/
|
|
18
|
+
readonly getValueLabel?: (value: number, max: number) => string;
|
|
19
|
+
readonly children?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export type IProgressComponentType<RootProps, IndicatorProps, RootRef = unknown, IndicatorRef = unknown> = ForwardRefExoticComponent<PropsWithoutRef<RootProps & InterfaceProgressProps> & RefAttributes<RootRef>> & {
|
|
22
|
+
Indicator: ForwardRefExoticComponent<PropsWithoutRef<IndicatorProps> & RefAttributes<IndicatorRef>>;
|
|
23
|
+
};
|
|
24
|
+
export type IProgressProps = InterfaceProgressProps;
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/progress/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,eAAe,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IACzE;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAChE,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,MAAM,sBAAsB,CAChC,SAAS,EACT,cAAc,EACd,OAAO,GAAG,OAAO,EACjB,YAAY,GAAG,OAAO,IACpB,yBAAyB,CAC3B,eAAe,CAAC,SAAS,GAAG,sBAAsB,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAC7E,GAAG;IACF,SAAS,EAAE,yBAAyB,CAClC,eAAe,CAAC,cAAc,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAC9D,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/primitives",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.36",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"module": "lib/module/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@react-native-aria/interactions": "^0.2.16",
|
|
58
58
|
"@react-stately/checkbox": "3.7.4",
|
|
59
59
|
"@react-stately/toggle": "3.9.4",
|
|
60
|
-
"@cdx-ui/utils": "0.0.1-alpha.
|
|
60
|
+
"@cdx-ui/utils": "0.0.1-alpha.36"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/react": "*",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldError = <T,>(BaseFormError: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => {
|
|
6
6
|
const { isInvalid, feedbackId, setHasFeedbackText } = useFormControlContext();
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldErrorIcon = <T,>(BaseFormErrorIcon: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormErrorIcon ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldErrorText = <T,>(BaseFormErrorText: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormErrorText ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldHelper = <T,>(BaseFormHelper: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => {
|
|
6
6
|
const { helpTextId, setHasHelpText, isInvalid } = useFormControlContext();
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createFieldHelperText = <T,>(BaseFormHelperText: React.ComponentType<T>) =>
|
|
5
5
|
forwardRef<unknown, { children?: React.ReactNode }>(({ children, ...props }, ref) => (
|
|
6
6
|
<BaseFormHelperText ref={ref} {...(props as T)}>
|
|
7
7
|
{children}
|
|
@@ -2,10 +2,10 @@ import type React from 'react';
|
|
|
2
2
|
import { forwardRef } from 'react';
|
|
3
3
|
import { useFormControlContext } from '@cdx-ui/utils';
|
|
4
4
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
5
|
-
import type {
|
|
5
|
+
import type { IFieldLabelProps } from './types';
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
forwardRef<unknown,
|
|
7
|
+
export const createFieldLabel = <T,>(BaseFormLabel: React.ComponentType<T>) =>
|
|
8
|
+
forwardRef<unknown, IFieldLabelProps & { children?: React.ReactNode }>(
|
|
9
9
|
({ children, htmlFor: htmlForProp, requiredIndicator, ...props }, ref) => {
|
|
10
10
|
const field = useFormControlContext();
|
|
11
11
|
const fieldId = field.id;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
2
|
import { useFormControlRoot, FormControlContext } from '@cdx-ui/utils';
|
|
3
3
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
4
|
-
import type {
|
|
4
|
+
import type { IFieldRootProps } from './types';
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const createFieldRoot = <T,>(BaseFormField: React.ComponentType<T>) =>
|
|
7
7
|
forwardRef(
|
|
8
|
-
({ children, ...props }:
|
|
8
|
+
({ children, ...props }: IFieldRootProps & { children?: React.ReactNode }, ref?: unknown) => {
|
|
9
9
|
const { htmlProps, ...context } = useFormControlRoot(props);
|
|
10
10
|
|
|
11
11
|
return (
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createFieldError } from './createFieldError';
|
|
3
|
+
import { createFieldErrorIcon } from './createFieldErrorIcon';
|
|
4
|
+
import { createFieldErrorText } from './createFieldErrorText';
|
|
5
|
+
import { createFieldRoot } from './createFieldRoot';
|
|
6
|
+
import { createFieldHelper } from './createFieldHelper';
|
|
7
|
+
import { createFieldHelperText } from './createFieldHelperText';
|
|
8
|
+
import { createFieldLabel } from './createFieldLabel';
|
|
9
|
+
import type { IFieldComponentType } from './types';
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
IFieldRootProps,
|
|
13
|
+
IFieldLabelProps,
|
|
14
|
+
IFieldHelperProps,
|
|
15
|
+
IFieldHelperTextProps,
|
|
16
|
+
IFieldErrorProps,
|
|
17
|
+
IFieldErrorTextProps,
|
|
18
|
+
IFieldErrorIconProps,
|
|
19
|
+
IFieldComponentType,
|
|
20
|
+
} from './types';
|
|
21
|
+
|
|
22
|
+
export function createField<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon>({
|
|
23
|
+
Root,
|
|
24
|
+
Label,
|
|
25
|
+
Helper,
|
|
26
|
+
HelperText,
|
|
27
|
+
Error,
|
|
28
|
+
ErrorText,
|
|
29
|
+
ErrorIcon,
|
|
30
|
+
}: {
|
|
31
|
+
Root: React.ComponentType<Root>;
|
|
32
|
+
Label: React.ComponentType<Label>;
|
|
33
|
+
Helper: React.ComponentType<Helper>;
|
|
34
|
+
HelperText: React.ComponentType<HelperText>;
|
|
35
|
+
Error: React.ComponentType<Error>;
|
|
36
|
+
ErrorText: React.ComponentType<ErrorText>;
|
|
37
|
+
ErrorIcon: React.ComponentType<ErrorIcon>;
|
|
38
|
+
}) {
|
|
39
|
+
const FieldRoot = createFieldRoot(Root);
|
|
40
|
+
FieldRoot.displayName = 'FieldPrimitive';
|
|
41
|
+
|
|
42
|
+
const FieldLabel = createFieldLabel(Label);
|
|
43
|
+
FieldLabel.displayName = 'FieldPrimitive.Label';
|
|
44
|
+
|
|
45
|
+
const FieldHelper = createFieldHelper(Helper);
|
|
46
|
+
FieldHelper.displayName = 'FieldPrimitive.Helper';
|
|
47
|
+
|
|
48
|
+
const FieldHelperText = createFieldHelperText(HelperText);
|
|
49
|
+
FieldHelperText.displayName = 'FieldPrimitive.HelperText';
|
|
50
|
+
|
|
51
|
+
const FieldError = createFieldError(Error);
|
|
52
|
+
FieldError.displayName = 'FieldPrimitive.Error';
|
|
53
|
+
|
|
54
|
+
const FieldErrorText = createFieldErrorText(ErrorText);
|
|
55
|
+
FieldErrorText.displayName = 'FieldPrimitive.ErrorText';
|
|
56
|
+
|
|
57
|
+
const FieldErrorIcon = createFieldErrorIcon(ErrorIcon);
|
|
58
|
+
FieldErrorIcon.displayName = 'FieldPrimitive.ErrorIcon';
|
|
59
|
+
|
|
60
|
+
return Object.assign(FieldRoot, {
|
|
61
|
+
Label: FieldLabel,
|
|
62
|
+
Helper: FieldHelper,
|
|
63
|
+
HelperText: FieldHelperText,
|
|
64
|
+
Error: FieldError,
|
|
65
|
+
ErrorText: FieldErrorText,
|
|
66
|
+
ErrorIcon: FieldErrorIcon,
|
|
67
|
+
}) as IFieldComponentType<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon>;
|
|
68
|
+
}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type { TextProps, ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Props for the Form container (`<form>` on web, `<View>` on RN).
|
|
6
|
-
* Does NOT provide field-level context — use `Form.Field` for that.
|
|
7
|
-
*
|
|
8
|
-
* Web-only submit props (`onSubmit`, `action`, `method`) belong in the
|
|
9
|
-
* platform-specific base component (`FormRoot.web.tsx`), not here.
|
|
10
|
-
*/
|
|
11
|
-
export interface IFormProps {}
|
|
12
|
-
|
|
13
4
|
/**
|
|
14
5
|
* Props for a single form field (`Form.Field`).
|
|
15
6
|
* Provides field-level context (name, validation state, ids) to children.
|
|
@@ -20,7 +11,7 @@ export interface IFormProps {}
|
|
|
20
11
|
*
|
|
21
12
|
* **Submit UX:** "focus first invalid on error" needs form-level validation state; not built in yet.
|
|
22
13
|
*/
|
|
23
|
-
export interface
|
|
14
|
+
export interface IFieldRootProps extends ViewProps {
|
|
24
15
|
/** Unique id for this field. Auto-generated if not provided. */
|
|
25
16
|
readonly id?: string;
|
|
26
17
|
/**
|
|
@@ -38,7 +29,7 @@ export interface IFormFieldProps extends ViewProps {
|
|
|
38
29
|
readonly isReadOnly?: boolean;
|
|
39
30
|
}
|
|
40
31
|
|
|
41
|
-
export interface
|
|
32
|
+
export interface IFieldLabelProps extends TextProps {
|
|
42
33
|
/**
|
|
43
34
|
* Associates the label with a control `id` on web (`<label htmlFor>`).
|
|
44
35
|
* If omitted, defaults to the same id `Input.Field` gets from form context: `fieldId + "-input"`.
|
|
@@ -52,41 +43,36 @@ export interface IFormLabelProps extends TextProps {
|
|
|
52
43
|
readonly requiredIndicator?: React.ReactNode;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
|
-
export interface
|
|
46
|
+
export interface IFieldHelperProps extends ViewProps {}
|
|
56
47
|
|
|
57
|
-
export interface
|
|
48
|
+
export interface IFieldHelperTextProps extends TextProps {}
|
|
58
49
|
|
|
59
|
-
export interface
|
|
50
|
+
export interface IFieldErrorProps extends ViewProps {}
|
|
60
51
|
|
|
61
|
-
export interface
|
|
52
|
+
export interface IFieldErrorTextProps extends TextProps {}
|
|
62
53
|
|
|
63
|
-
export interface
|
|
54
|
+
export interface IFieldErrorIconProps extends ViewProps {}
|
|
64
55
|
|
|
65
|
-
export type
|
|
66
|
-
Root
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
>;
|
|
87
|
-
ErrorIcon: React.ForwardRefExoticComponent<
|
|
88
|
-
InnerForwardRefExoticComponent<ErrorIcon> & IFormErrorIconProps
|
|
89
|
-
>;
|
|
90
|
-
};
|
|
56
|
+
export type IFieldComponentType<Root, Label, Helper, HelperText, Error, ErrorText, ErrorIcon> =
|
|
57
|
+
React.ForwardRefExoticComponent<InnerForwardRefExoticComponent<Root> & IFieldRootProps> & {
|
|
58
|
+
Label: React.ForwardRefExoticComponent<
|
|
59
|
+
InnerForwardRefExoticComponent<Label> & IFieldLabelProps
|
|
60
|
+
>;
|
|
61
|
+
Helper: React.ForwardRefExoticComponent<
|
|
62
|
+
InnerForwardRefExoticComponent<Helper> & IFieldHelperProps
|
|
63
|
+
>;
|
|
64
|
+
HelperText: React.ForwardRefExoticComponent<
|
|
65
|
+
InnerForwardRefExoticComponent<HelperText> & IFieldHelperTextProps
|
|
66
|
+
>;
|
|
67
|
+
Error: React.ForwardRefExoticComponent<
|
|
68
|
+
InnerForwardRefExoticComponent<Error> & IFieldErrorProps
|
|
69
|
+
>;
|
|
70
|
+
ErrorText: React.ForwardRefExoticComponent<
|
|
71
|
+
InnerForwardRefExoticComponent<ErrorText> & IFieldErrorTextProps
|
|
72
|
+
>;
|
|
73
|
+
ErrorIcon: React.ForwardRefExoticComponent<
|
|
74
|
+
InnerForwardRefExoticComponent<ErrorIcon> & IFieldErrorIconProps
|
|
75
|
+
>;
|
|
76
|
+
};
|
|
91
77
|
|
|
92
78
|
type InnerForwardRefExoticComponent<T> = React.PropsWithoutRef<T> & React.RefAttributes<unknown>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IFormRootProps, IFormComponentType } from './types';
|
|
3
3
|
|
|
4
4
|
// TODO: Handle web submission (button type submit)
|
|
5
5
|
|
|
6
|
-
export const createFormRoot = <T,>(BaseFormRoot: React.ComponentType<T>) =>
|
|
6
|
+
export const createFormRoot = <T,>(BaseFormRoot: React.ComponentType<T>): IFormComponentType<T> =>
|
|
7
7
|
forwardRef(
|
|
8
|
-
({ children, ...props }:
|
|
8
|
+
({ children, ...props }: IFormRootProps & { children?: React.ReactNode }, ref?: unknown) => (
|
|
9
9
|
<BaseFormRoot ref={ref} {...(props as T)}>
|
|
10
10
|
{children}
|
|
11
11
|
</BaseFormRoot>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createFormRoot } from './createFormRoot';
|
|
3
|
+
|
|
4
|
+
export type { IFormRootProps, IFormComponentType } from './types';
|
|
5
|
+
|
|
6
|
+
export function createForm<Root>({ Root }: { Root: React.ComponentType<Root> }) {
|
|
7
|
+
const FormRoot = createFormRoot(Root);
|
|
8
|
+
|
|
9
|
+
FormRoot.displayName = 'FormPrimitive';
|
|
10
|
+
|
|
11
|
+
return FormRoot;
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for the Form container (`<form>` on web, `<View>` on RN).
|
|
5
|
+
* Does NOT provide field-level context — use `Form.Field` for that.
|
|
6
|
+
*
|
|
7
|
+
* Web-only submit props (`onSubmit`, `action`, `method`) belong in the
|
|
8
|
+
* platform-specific base component (`FormRoot.web.tsx`), not here.
|
|
9
|
+
*/
|
|
10
|
+
export interface IFormRootProps {}
|
|
11
|
+
|
|
12
|
+
export type IFormComponentType<Root> = React.ForwardRefExoticComponent<
|
|
13
|
+
InnerForwardRefExoticComponent<Root> & IFormRootProps
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
type InnerForwardRefExoticComponent<T> = React.PropsWithoutRef<T> & React.RefAttributes<unknown>;
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,13 @@ export * from './avatar';
|
|
|
2
2
|
export * from './button';
|
|
3
3
|
export * from './checkbox';
|
|
4
4
|
export * from './dialog';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './field';
|
|
6
|
+
export * from './form';
|
|
6
7
|
export * from './input';
|
|
7
8
|
export * from './link';
|
|
8
9
|
export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
|
|
9
10
|
export * from './select';
|
|
10
11
|
export * from './switch';
|
|
12
|
+
export * from './progress';
|
|
11
13
|
export type { InteractionState } from './types';
|
|
12
14
|
export { dataAttributes } from './utils/dataAttributes';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext } from '@cdx-ui/utils';
|
|
2
|
+
import type { ProgressDataState } from './types';
|
|
3
|
+
|
|
4
|
+
export interface ProgressContextValue {
|
|
5
|
+
/** Clamped value in [0, max], or null when indeterminate */
|
|
6
|
+
readonly value: number | null;
|
|
7
|
+
readonly max: number;
|
|
8
|
+
readonly percent: number;
|
|
9
|
+
readonly state: ProgressDataState;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const [ProgressProvider, useProgressContext] =
|
|
13
|
+
createContext<ProgressContextValue>('ProgressContext');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useMemo, type PropsWithoutRef } from 'react';
|
|
3
|
+
import type { ViewStyle } from 'react-native';
|
|
4
|
+
import { dataAttributes } from '../utils/dataAttributes';
|
|
5
|
+
import { useProgressContext } from './context';
|
|
6
|
+
|
|
7
|
+
type PercentString = `${number}%`;
|
|
8
|
+
|
|
9
|
+
export const createProgressIndicator = <T, R = unknown>(BaseIndicator: React.ComponentType<T>) =>
|
|
10
|
+
forwardRef<R, PropsWithoutRef<T>>((props, ref) => {
|
|
11
|
+
const { style, ...rest } = props as PropsWithoutRef<T> & { style?: object };
|
|
12
|
+
const { percent, state, max, value } = useProgressContext();
|
|
13
|
+
|
|
14
|
+
const filledStyle = useMemo((): ViewStyle => {
|
|
15
|
+
const pct = `${String(percent)}%` as PercentString;
|
|
16
|
+
return { width: pct, height: '100%' };
|
|
17
|
+
}, [percent]);
|
|
18
|
+
|
|
19
|
+
const dataAttrs = dataAttributes({
|
|
20
|
+
state,
|
|
21
|
+
value: value === null ? undefined : String(value),
|
|
22
|
+
max: String(max),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<BaseIndicator
|
|
27
|
+
ref={ref as React.Ref<R>}
|
|
28
|
+
{...({
|
|
29
|
+
...rest,
|
|
30
|
+
...dataAttrs,
|
|
31
|
+
style: [filledStyle, style],
|
|
32
|
+
} as T)}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, useMemo, type PropsWithoutRef } from 'react';
|
|
3
|
+
import { dataAttributes } from '../utils/dataAttributes';
|
|
4
|
+
import { ProgressProvider } from './context';
|
|
5
|
+
import type { InterfaceProgressProps, ProgressDataState } from './types';
|
|
6
|
+
|
|
7
|
+
function clamp(n: number, min: number, max: number): number {
|
|
8
|
+
return Math.min(max, Math.max(min, n));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function resolveState(
|
|
12
|
+
value: number | null,
|
|
13
|
+
max: number,
|
|
14
|
+
clamped: number | null,
|
|
15
|
+
): ProgressDataState {
|
|
16
|
+
if (value === null) {
|
|
17
|
+
return 'indeterminate';
|
|
18
|
+
}
|
|
19
|
+
if (max <= 0) {
|
|
20
|
+
return 'complete';
|
|
21
|
+
}
|
|
22
|
+
if (clamped !== null && clamped >= max) {
|
|
23
|
+
return 'complete';
|
|
24
|
+
}
|
|
25
|
+
return 'loading';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function defaultGetValueLabel(value: number, max: number): string {
|
|
29
|
+
if (max <= 0) {
|
|
30
|
+
return '0%';
|
|
31
|
+
}
|
|
32
|
+
return `${String(Math.round((value / max) * 100))}%`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const createProgressRoot = <T, R = unknown>(BaseRoot: React.ComponentType<T>) =>
|
|
36
|
+
forwardRef<R, PropsWithoutRef<T> & InterfaceProgressProps>((props, ref) => {
|
|
37
|
+
const {
|
|
38
|
+
value: valueProp = 0,
|
|
39
|
+
max: maxProp = 100,
|
|
40
|
+
getValueLabel = defaultGetValueLabel,
|
|
41
|
+
children,
|
|
42
|
+
accessibilityRole = 'progressbar',
|
|
43
|
+
accessibilityValue: accessibilityValueProp,
|
|
44
|
+
role = 'progressbar',
|
|
45
|
+
...restProps
|
|
46
|
+
} = props;
|
|
47
|
+
const max = maxProp > 0 ? maxProp : 0;
|
|
48
|
+
const isIndeterminate = valueProp === null;
|
|
49
|
+
const clampedValue =
|
|
50
|
+
valueProp === null ? null : clamp(Number.isFinite(valueProp) ? valueProp : 0, 0, max);
|
|
51
|
+
|
|
52
|
+
const percent = useMemo(() => {
|
|
53
|
+
if (clampedValue === null || max <= 0) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
return (clampedValue / max) * 100;
|
|
57
|
+
}, [clampedValue, max]);
|
|
58
|
+
|
|
59
|
+
const state = useMemo(
|
|
60
|
+
() => resolveState(valueProp, max, clampedValue),
|
|
61
|
+
[valueProp, max, clampedValue],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const contextValue = useMemo(
|
|
65
|
+
() => ({
|
|
66
|
+
value: clampedValue,
|
|
67
|
+
max,
|
|
68
|
+
percent,
|
|
69
|
+
state,
|
|
70
|
+
}),
|
|
71
|
+
[clampedValue, max, percent, state],
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const dataAttrs = dataAttributes({
|
|
75
|
+
state,
|
|
76
|
+
value: clampedValue === null ? undefined : String(clampedValue),
|
|
77
|
+
max: String(max),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const accessibilityValue = useMemo(() => {
|
|
81
|
+
if (accessibilityValueProp !== undefined) {
|
|
82
|
+
return accessibilityValueProp;
|
|
83
|
+
}
|
|
84
|
+
if (isIndeterminate || clampedValue === null) {
|
|
85
|
+
return { min: 0, max, text: 'Indeterminate' };
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
min: 0,
|
|
89
|
+
max,
|
|
90
|
+
now: clampedValue,
|
|
91
|
+
text: getValueLabel(clampedValue, max),
|
|
92
|
+
};
|
|
93
|
+
}, [accessibilityValueProp, isIndeterminate, clampedValue, max, getValueLabel]);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<ProgressProvider value={contextValue}>
|
|
97
|
+
<BaseRoot
|
|
98
|
+
ref={ref as React.Ref<R>}
|
|
99
|
+
{...(restProps as T)}
|
|
100
|
+
role={role}
|
|
101
|
+
accessibilityRole={accessibilityRole}
|
|
102
|
+
accessibilityValue={accessibilityValue}
|
|
103
|
+
{...dataAttrs}
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</BaseRoot>
|
|
107
|
+
</ProgressProvider>
|
|
108
|
+
);
|
|
109
|
+
});
|