@salt-ds/core 1.9.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/checkbox/Checkbox.css.js +1 -1
- package/dist-cjs/checkbox/Checkbox.js +1 -1
- package/dist-cjs/checkbox/Checkbox.js.map +1 -1
- package/dist-cjs/flex-layout/FlexLayout.css.js +1 -1
- package/dist-cjs/index.js +2 -0
- package/dist-cjs/index.js.map +1 -1
- package/dist-cjs/radio-button/RadioButton.css.js +1 -1
- package/dist-cjs/spinner/Spinner.css.js +1 -1
- package/dist-cjs/spinner/Spinner.js +13 -3
- package/dist-cjs/spinner/Spinner.js.map +1 -1
- package/dist-cjs/spinner/svgSpinners/SpinnerSVG.js +57 -47
- package/dist-cjs/spinner/svgSpinners/SpinnerSVG.js.map +1 -1
- package/dist-cjs/split-layout/SplitLayout.css.js +6 -0
- package/dist-cjs/split-layout/SplitLayout.css.js.map +1 -0
- package/dist-cjs/split-layout/SplitLayout.js +18 -1
- package/dist-cjs/split-layout/SplitLayout.js.map +1 -1
- package/dist-cjs/stack-layout/StackLayout.css.js +1 -1
- package/dist-cjs/switch/Switch.css.js +6 -0
- package/dist-cjs/switch/Switch.css.js.map +1 -0
- package/dist-cjs/switch/Switch.js +126 -0
- package/dist-cjs/switch/Switch.js.map +1 -0
- package/dist-cjs/viewport/ViewportProvider.js +1 -0
- package/dist-cjs/viewport/ViewportProvider.js.map +1 -1
- package/dist-es/checkbox/Checkbox.css.js +1 -1
- package/dist-es/checkbox/Checkbox.js +1 -1
- package/dist-es/checkbox/Checkbox.js.map +1 -1
- package/dist-es/flex-layout/FlexLayout.css.js +1 -1
- package/dist-es/index.js +1 -0
- package/dist-es/index.js.map +1 -1
- package/dist-es/radio-button/RadioButton.css.js +1 -1
- package/dist-es/spinner/Spinner.css.js +1 -1
- package/dist-es/spinner/Spinner.js +13 -3
- package/dist-es/spinner/Spinner.js.map +1 -1
- package/dist-es/spinner/svgSpinners/SpinnerSVG.js +57 -47
- package/dist-es/spinner/svgSpinners/SpinnerSVG.js.map +1 -1
- package/dist-es/split-layout/SplitLayout.css.js +4 -0
- package/dist-es/split-layout/SplitLayout.css.js.map +1 -0
- package/dist-es/split-layout/SplitLayout.js +18 -1
- package/dist-es/split-layout/SplitLayout.js.map +1 -1
- package/dist-es/stack-layout/StackLayout.css.js +1 -1
- package/dist-es/switch/Switch.css.js +4 -0
- package/dist-es/switch/Switch.css.js.map +1 -0
- package/dist-es/switch/Switch.js +122 -0
- package/dist-es/switch/Switch.js.map +1 -0
- package/dist-es/viewport/ViewportProvider.js +1 -0
- package/dist-es/viewport/ViewportProvider.js.map +1 -1
- package/dist-types/index.d.ts +1 -0
- package/dist-types/spinner/Spinner.d.ts +6 -4
- package/dist-types/spinner/svgSpinners/SpinnerSVG.d.ts +8 -2
- package/dist-types/switch/Switch.d.ts +45 -0
- package/dist-types/switch/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import '../form-field-context/FormFieldContext.js';
|
|
5
|
+
import { useFormFieldProps } from '../form-field-context/useFormFieldProps.js';
|
|
6
|
+
import { makePrefixer } from '../utils/makePrefixer.js';
|
|
7
|
+
import { useControlled } from '../utils/useControlled.js';
|
|
8
|
+
import '../utils/useFloatingUI/useFloatingUI.js';
|
|
9
|
+
import '../utils/useId.js';
|
|
10
|
+
import { useDensity } from '../salt-provider/SaltProvider.js';
|
|
11
|
+
import '../viewport/ViewportProvider.js';
|
|
12
|
+
import { useWindow } from '@salt-ds/window';
|
|
13
|
+
import { useComponentCssInjection } from '@salt-ds/styles';
|
|
14
|
+
import css_248z from './Switch.css.js';
|
|
15
|
+
import { SuccessSmallSolidIcon, SuccessSolidIcon } from '@salt-ds/icons';
|
|
16
|
+
|
|
17
|
+
const withBaseName = makePrefixer("saltSwitch");
|
|
18
|
+
function CheckedIcon(props) {
|
|
19
|
+
const density = useDensity();
|
|
20
|
+
return density === "high" ? /* @__PURE__ */ jsx(SuccessSmallSolidIcon, {
|
|
21
|
+
...props
|
|
22
|
+
}) : /* @__PURE__ */ jsx(SuccessSolidIcon, {
|
|
23
|
+
...props
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const Switch = forwardRef(function Switch2(props, ref) {
|
|
27
|
+
const {
|
|
28
|
+
checked: checkedProp,
|
|
29
|
+
className,
|
|
30
|
+
defaultChecked,
|
|
31
|
+
disabled: disabledProp,
|
|
32
|
+
inputProps = {},
|
|
33
|
+
label,
|
|
34
|
+
name,
|
|
35
|
+
onBlur,
|
|
36
|
+
onChange,
|
|
37
|
+
onFocus,
|
|
38
|
+
value,
|
|
39
|
+
...rest
|
|
40
|
+
} = props;
|
|
41
|
+
const targetWindow = useWindow();
|
|
42
|
+
useComponentCssInjection({
|
|
43
|
+
testId: "salt-switch",
|
|
44
|
+
css: css_248z,
|
|
45
|
+
window: targetWindow
|
|
46
|
+
});
|
|
47
|
+
const {
|
|
48
|
+
"aria-describedby": inputDescribedBy,
|
|
49
|
+
"aria-labelledby": inputLabelledBy,
|
|
50
|
+
className: inputClassName,
|
|
51
|
+
onChange: inputOnChange,
|
|
52
|
+
...restInputProps
|
|
53
|
+
} = inputProps;
|
|
54
|
+
const [checked, setChecked] = useControlled({
|
|
55
|
+
controlled: checkedProp,
|
|
56
|
+
default: Boolean(defaultChecked),
|
|
57
|
+
name: "Switch",
|
|
58
|
+
state: "checked"
|
|
59
|
+
});
|
|
60
|
+
const { a11yProps: formFieldA11yProps, disabled: formFieldDisabled } = useFormFieldProps();
|
|
61
|
+
const disabled = formFieldDisabled != null ? formFieldDisabled : disabledProp;
|
|
62
|
+
const handleChange = (event) => {
|
|
63
|
+
if (event.nativeEvent.defaultPrevented) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const value2 = event.target.checked;
|
|
67
|
+
setChecked(value2);
|
|
68
|
+
onChange == null ? void 0 : onChange(event);
|
|
69
|
+
inputOnChange == null ? void 0 : inputOnChange(event);
|
|
70
|
+
};
|
|
71
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
72
|
+
className: clsx(
|
|
73
|
+
withBaseName(),
|
|
74
|
+
{
|
|
75
|
+
[withBaseName("disabled")]: disabled,
|
|
76
|
+
[withBaseName("checked")]: checked
|
|
77
|
+
},
|
|
78
|
+
className
|
|
79
|
+
),
|
|
80
|
+
ref,
|
|
81
|
+
...rest,
|
|
82
|
+
children: [
|
|
83
|
+
/* @__PURE__ */ jsx("input", {
|
|
84
|
+
"aria-describedby": clsx(
|
|
85
|
+
formFieldA11yProps == null ? void 0 : formFieldA11yProps["aria-describedby"],
|
|
86
|
+
inputDescribedBy
|
|
87
|
+
),
|
|
88
|
+
"aria-labelledby": clsx(
|
|
89
|
+
formFieldA11yProps == null ? void 0 : formFieldA11yProps["aria-labelledby"],
|
|
90
|
+
inputLabelledBy
|
|
91
|
+
),
|
|
92
|
+
name,
|
|
93
|
+
value,
|
|
94
|
+
checked,
|
|
95
|
+
className: clsx(withBaseName("input"), inputClassName),
|
|
96
|
+
defaultChecked,
|
|
97
|
+
disabled,
|
|
98
|
+
onBlur,
|
|
99
|
+
onChange: handleChange,
|
|
100
|
+
onFocus,
|
|
101
|
+
type: "checkbox",
|
|
102
|
+
...restInputProps
|
|
103
|
+
}),
|
|
104
|
+
/* @__PURE__ */ jsx("span", {
|
|
105
|
+
className: withBaseName("track"),
|
|
106
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
107
|
+
className: withBaseName("thumb"),
|
|
108
|
+
children: checked && /* @__PURE__ */ jsx(CheckedIcon, {
|
|
109
|
+
className: withBaseName("icon")
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
}),
|
|
113
|
+
/* @__PURE__ */ jsx("span", {
|
|
114
|
+
className: withBaseName("label"),
|
|
115
|
+
children: label
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export { Switch };
|
|
122
|
+
//# sourceMappingURL=Switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Switch.js","sources":["../src/switch/Switch.tsx"],"sourcesContent":["import { clsx } from \"clsx\";\nimport {\n ChangeEventHandler,\n ComponentPropsWithoutRef,\n FocusEventHandler,\n forwardRef,\n ReactNode,\n} from \"react\";\nimport { useFormFieldProps } from \"../form-field-context\";\nimport { makePrefixer, useControlled } from \"../utils\";\nimport { useDensity } from \"../salt-provider\";\nimport { useWindow } from \"@salt-ds/window\";\nimport { useComponentCssInjection } from \"@salt-ds/styles\";\n\nimport switchCss from \"./Switch.css\";\nimport {\n IconProps,\n SuccessSmallSolidIcon,\n SuccessSolidIcon,\n} from \"@salt-ds/icons\";\n\nexport interface SwitchProps\n extends Omit<\n ComponentPropsWithoutRef<\"label\">,\n \"children\" | \"onFocus\" | \"onBlur\" | \"onChange\"\n > {\n /**\n * If `true`, the checkbox will be checked.\n */\n checked?: boolean;\n /**\n * Whether the checkbox component is checked by default\n * This will be disregarded if checked is already set.\n */\n defaultChecked?: boolean;\n /**\n * If `true`, the checkbox will be disabled.\n */\n disabled?: boolean;\n /**\n * Properties applied to the input element.\n */\n inputProps?: Partial<ComponentPropsWithoutRef<\"input\">>;\n /**\n * The label to be shown next to the checkbox.\n */\n label?: ReactNode;\n /**\n * The name applied to the input.\n */\n name?: string;\n /**\n * Callback when checkbox loses focus.\n */\n onBlur?: FocusEventHandler<HTMLInputElement>;\n /**\n * Callback when checked state is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Callback when checkbox gains focus.\n */\n onFocus?: FocusEventHandler<HTMLInputElement>;\n /**\n * The value of the checkbox.\n */\n value?: string;\n}\n\nconst withBaseName = makePrefixer(\"saltSwitch\");\n\nfunction CheckedIcon(props: IconProps) {\n const density = useDensity();\n return density === \"high\" ? (\n <SuccessSmallSolidIcon {...props} />\n ) : (\n <SuccessSolidIcon {...props} />\n );\n}\n\nexport const Switch = forwardRef<HTMLLabelElement, SwitchProps>(function Switch(\n props,\n ref\n) {\n const {\n checked: checkedProp,\n className,\n defaultChecked,\n disabled: disabledProp,\n inputProps = {},\n label,\n name,\n onBlur,\n onChange,\n onFocus,\n value,\n ...rest\n } = props;\n\n const targetWindow = useWindow();\n useComponentCssInjection({\n testId: \"salt-switch\",\n css: switchCss,\n window: targetWindow,\n });\n\n const {\n \"aria-describedby\": inputDescribedBy,\n \"aria-labelledby\": inputLabelledBy,\n className: inputClassName,\n onChange: inputOnChange,\n ...restInputProps\n } = inputProps;\n\n const [checked, setChecked] = useControlled({\n controlled: checkedProp,\n default: Boolean(defaultChecked),\n name: \"Switch\",\n state: \"checked\",\n });\n\n const { a11yProps: formFieldA11yProps, disabled: formFieldDisabled } =\n useFormFieldProps();\n\n const disabled = formFieldDisabled ?? disabledProp;\n\n const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {\n // Workaround for https://github.com/facebook/react/issues/9023\n if (event.nativeEvent.defaultPrevented) {\n return;\n }\n\n const value = event.target.checked;\n setChecked(value);\n onChange?.(event);\n inputOnChange?.(event);\n };\n\n return (\n <label\n className={clsx(\n withBaseName(),\n {\n [withBaseName(\"disabled\")]: disabled,\n [withBaseName(\"checked\")]: checked,\n },\n className\n )}\n ref={ref}\n {...rest}\n >\n <input\n aria-describedby={clsx(\n formFieldA11yProps?.[\"aria-describedby\"],\n inputDescribedBy\n )}\n aria-labelledby={clsx(\n formFieldA11yProps?.[\"aria-labelledby\"],\n inputLabelledBy\n )}\n name={name}\n value={value}\n checked={checked}\n className={clsx(withBaseName(\"input\"), inputClassName)}\n defaultChecked={defaultChecked}\n disabled={disabled}\n onBlur={onBlur}\n onChange={handleChange}\n onFocus={onFocus}\n type=\"checkbox\"\n {...restInputProps}\n />\n <span className={withBaseName(\"track\")}>\n <span className={withBaseName(\"thumb\")}>\n {checked && <CheckedIcon className={withBaseName(\"icon\")} />}\n </span>\n </span>\n <span className={withBaseName(\"label\")}>{label}</span>\n </label>\n );\n});\n"],"names":["Switch","switchCss","value"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewportProvider.js","sources":["../src/viewport/ViewportProvider.tsx"],"sourcesContent":["import { createContext, useState, useContext, ReactNode } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"../utils\";\n\nconst ViewportContext = createContext<number | null>(null);\n\ntype ViewportProviderProps = {\n children?: ReactNode;\n};\n\nconst ViewportProvider = ({ children }: ViewportProviderProps) => {\n // Get value directly from the ViewportContext so we can detect if the value is null (no inherited ViewportProvider)\n const existingViewport = useContext(ViewportContext);\n const [viewport, setViewport] = useState(existingViewport);\n\n const noExistingViewport = existingViewport === null;\n const viewportValue = existingViewport || viewport || 0;\n\n useIsomorphicLayoutEffect(() => {\n let observer: ResizeObserver | null = null;\n\n if (noExistingViewport) {\n observer = new ResizeObserver(\n (observerEntries: ResizeObserverEntry[]) => {\n setViewport(observerEntries[0].contentRect.width);\n }\n );\n\n observer.observe(document.body);\n }\n\n return () => {\n if (observer) {\n observer.disconnect();\n }\n };\n }, [noExistingViewport]);\n\n return (\n <ViewportContext.Provider value={viewportValue}>\n {children}\n </ViewportContext.Provider>\n );\n};\n\nconst useViewport = (): number => {\n const value = useContext(ViewportContext);\n return value === null ? 0 : value;\n};\n\nexport { ViewportProvider, ViewportContext, useViewport };\n"],"names":[],"mappings":";;;;;;;;AAGM,MAAA,eAAA,GAAkB,cAA6B,IAAI,EAAA;AAMzD,MAAM,gBAAmB,GAAA,CAAC,EAAE,QAAA,EAAsC,KAAA;AAEhE,EAAM,MAAA,gBAAA,GAAmB,WAAW,eAAe,CAAA,CAAA;AACnD,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,gBAAgB,CAAA,CAAA;AAEzD,EAAA,MAAM,qBAAqB,gBAAqB,KAAA,IAAA,CAAA;AAChD,EAAM,MAAA,aAAA,GAAgB,oBAAoB,QAAY,IAAA,CAAA,CAAA;AAEtD,EAAA,yBAAA,CAA0B,MAAM;AAC9B,IAAA,IAAI,QAAkC,GAAA,IAAA,CAAA;AAEtC,IAAA,IAAI,kBAAoB,EAAA;AACtB,MAAA,QAAA,GAAW,IAAI,cAAA;AAAA,QACb,CAAC,eAA2C,KAAA;AAC1C,UAAY,WAAA,CAAA,eAAA,CAAgB,CAAG,CAAA,CAAA,WAAA,CAAY,KAAK,CAAA,CAAA;AAAA,SAClD;AAAA,OACF,CAAA;AAEA,MAAS,QAAA,CAAA,OAAA,CAAQ,SAAS,IAAI,CAAA,CAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"ViewportProvider.js","sources":["../src/viewport/ViewportProvider.tsx"],"sourcesContent":["import { createContext, useState, useContext, ReactNode } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"../utils\";\n\nconst ViewportContext = createContext<number | null>(null);\n\ntype ViewportProviderProps = {\n children?: ReactNode;\n};\n\nconst ViewportProvider = ({ children }: ViewportProviderProps) => {\n // Get value directly from the ViewportContext so we can detect if the value is null (no inherited ViewportProvider)\n const existingViewport = useContext(ViewportContext);\n const [viewport, setViewport] = useState(existingViewport);\n\n const noExistingViewport = existingViewport === null;\n const viewportValue = existingViewport || viewport || 0;\n\n useIsomorphicLayoutEffect(() => {\n let observer: ResizeObserver | null = null;\n\n if (noExistingViewport) {\n observer = new ResizeObserver(\n (observerEntries: ResizeObserverEntry[]) => {\n setViewport(observerEntries[0].contentRect.width);\n }\n );\n\n observer.observe(document.body);\n setViewport(document.body.getBoundingClientRect().width);\n }\n\n return () => {\n if (observer) {\n observer.disconnect();\n }\n };\n }, [noExistingViewport]);\n\n return (\n <ViewportContext.Provider value={viewportValue}>\n {children}\n </ViewportContext.Provider>\n );\n};\n\nconst useViewport = (): number => {\n const value = useContext(ViewportContext);\n return value === null ? 0 : value;\n};\n\nexport { ViewportProvider, ViewportContext, useViewport };\n"],"names":[],"mappings":";;;;;;;;AAGM,MAAA,eAAA,GAAkB,cAA6B,IAAI,EAAA;AAMzD,MAAM,gBAAmB,GAAA,CAAC,EAAE,QAAA,EAAsC,KAAA;AAEhE,EAAM,MAAA,gBAAA,GAAmB,WAAW,eAAe,CAAA,CAAA;AACnD,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAS,gBAAgB,CAAA,CAAA;AAEzD,EAAA,MAAM,qBAAqB,gBAAqB,KAAA,IAAA,CAAA;AAChD,EAAM,MAAA,aAAA,GAAgB,oBAAoB,QAAY,IAAA,CAAA,CAAA;AAEtD,EAAA,yBAAA,CAA0B,MAAM;AAC9B,IAAA,IAAI,QAAkC,GAAA,IAAA,CAAA;AAEtC,IAAA,IAAI,kBAAoB,EAAA;AACtB,MAAA,QAAA,GAAW,IAAI,cAAA;AAAA,QACb,CAAC,eAA2C,KAAA;AAC1C,UAAY,WAAA,CAAA,eAAA,CAAgB,CAAG,CAAA,CAAA,WAAA,CAAY,KAAK,CAAA,CAAA;AAAA,SAClD;AAAA,OACF,CAAA;AAEA,MAAS,QAAA,CAAA,OAAA,CAAQ,SAAS,IAAI,CAAA,CAAA;AAC9B,MAAA,WAAA,CAAY,QAAS,CAAA,IAAA,CAAK,qBAAsB,EAAA,CAAE,KAAK,CAAA,CAAA;AAAA,KACzD;AAEA,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,QAAU,EAAA;AACZ,QAAA,QAAA,CAAS,UAAW,EAAA,CAAA;AAAA,OACtB;AAAA,KACF,CAAA;AAAA,GACF,EAAG,CAAC,kBAAkB,CAAC,CAAA,CAAA;AAEvB,EACE,uBAAA,GAAA,CAAC,gBAAgB,QAAhB,EAAA;AAAA,IAAyB,KAAO,EAAA,aAAA;AAAA,IAC9B,QAAA;AAAA,GACH,CAAA,CAAA;AAEJ,EAAA;AAEA,MAAM,cAAc,MAAc;AAChC,EAAM,MAAA,KAAA,GAAQ,WAAW,eAAe,CAAA,CAAA;AACxC,EAAO,OAAA,KAAA,KAAU,OAAO,CAAI,GAAA,KAAA,CAAA;AAC9B;;;;"}
|
package/dist-types/index.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { HTMLAttributes } from "react";
|
|
|
3
3
|
* Spinner component, provides an indeterminate loading indicator
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* <Spinner size="
|
|
6
|
+
* <Spinner size="small" | "medium" | "large" />
|
|
7
7
|
*/
|
|
8
|
-
export declare const SpinnerSizeValues: readonly ["default", "large"];
|
|
9
|
-
|
|
8
|
+
export declare const SpinnerSizeValues: readonly ["default", "large", "small", "medium"];
|
|
9
|
+
declare type SpinnerSize = (typeof SpinnerSizeValues)[number];
|
|
10
|
+
export declare type SpinnerSVGSize = Exclude<SpinnerSize, "default">;
|
|
10
11
|
export interface SpinnerProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
12
|
/**
|
|
12
13
|
* Determines the interval on which the component will continue to announce the aria-label. Defaults to 5000ms (5s)
|
|
@@ -33,7 +34,7 @@ export interface SpinnerProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
33
34
|
*/
|
|
34
35
|
role?: string;
|
|
35
36
|
/**
|
|
36
|
-
* Determines the size of the spinner. Must be one of: 'default', 'large'.
|
|
37
|
+
* Determines the size of the spinner. Must be one of: 'default', 'large', 'small', 'medium'.
|
|
37
38
|
*/
|
|
38
39
|
size?: SpinnerSize;
|
|
39
40
|
/**
|
|
@@ -42,3 +43,4 @@ export interface SpinnerProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
42
43
|
id?: string;
|
|
43
44
|
}
|
|
44
45
|
export declare const Spinner: import("react").ForwardRefExoticComponent<SpinnerProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
46
|
+
export {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { SVGAttributes } from "react";
|
|
2
|
-
|
|
2
|
+
import { SpinnerSVGSize } from "../Spinner";
|
|
3
|
+
import { Density } from "../../theme";
|
|
4
|
+
interface SpinnerProps {
|
|
3
5
|
id?: string;
|
|
4
6
|
rest?: Omit<SVGAttributes<SVGSVGElement>, "id">;
|
|
5
|
-
|
|
7
|
+
size: SpinnerSVGSize;
|
|
8
|
+
density: Density;
|
|
9
|
+
}
|
|
10
|
+
export declare const SpinnerSVG: ({ id, rest, size, density, }: SpinnerProps) => JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ChangeEventHandler, ComponentPropsWithoutRef, FocusEventHandler, ReactNode } from "react";
|
|
2
|
+
export interface SwitchProps extends Omit<ComponentPropsWithoutRef<"label">, "children" | "onFocus" | "onBlur" | "onChange"> {
|
|
3
|
+
/**
|
|
4
|
+
* If `true`, the checkbox will be checked.
|
|
5
|
+
*/
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the checkbox component is checked by default
|
|
9
|
+
* This will be disregarded if checked is already set.
|
|
10
|
+
*/
|
|
11
|
+
defaultChecked?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* If `true`, the checkbox will be disabled.
|
|
14
|
+
*/
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Properties applied to the input element.
|
|
18
|
+
*/
|
|
19
|
+
inputProps?: Partial<ComponentPropsWithoutRef<"input">>;
|
|
20
|
+
/**
|
|
21
|
+
* The label to be shown next to the checkbox.
|
|
22
|
+
*/
|
|
23
|
+
label?: ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* The name applied to the input.
|
|
26
|
+
*/
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Callback when checkbox loses focus.
|
|
30
|
+
*/
|
|
31
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
32
|
+
/**
|
|
33
|
+
* Callback when checked state is changed.
|
|
34
|
+
*/
|
|
35
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
36
|
+
/**
|
|
37
|
+
* Callback when checkbox gains focus.
|
|
38
|
+
*/
|
|
39
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
40
|
+
/**
|
|
41
|
+
* The value of the checkbox.
|
|
42
|
+
*/
|
|
43
|
+
value?: string;
|
|
44
|
+
}
|
|
45
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<SwitchProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Switch";
|