@hebium-ui/react 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -2
- package/dist/components/alert/alert.d.ts +44 -0
- package/dist/components/alert/alert.js +45 -0
- package/dist/components/alert/alert.js.map +1 -0
- package/dist/components/alert/index.d.ts +2 -0
- package/dist/components/anchor/anchor.d.ts +30 -0
- package/dist/components/anchor/anchor.js +25 -0
- package/dist/components/anchor/anchor.js.map +1 -0
- package/dist/components/anchor/index.d.ts +2 -0
- package/dist/components/avatar/avatar.d.ts +16 -0
- package/dist/components/avatar/avatar.js +50 -0
- package/dist/components/avatar/avatar.js.map +1 -0
- package/dist/components/avatar/index.d.ts +2 -0
- package/dist/components/blockquote/blockquote.d.ts +28 -0
- package/dist/components/blockquote/blockquote.js +29 -0
- package/dist/components/blockquote/blockquote.js.map +1 -0
- package/dist/components/blockquote/index.d.ts +2 -0
- package/dist/components/button/button.d.ts +30 -0
- package/dist/components/button/button.js +25 -0
- package/dist/components/button/button.js.map +1 -0
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/checkbox/checkbox.d.ts +33 -0
- package/dist/components/checkbox/checkbox.js +68 -0
- package/dist/components/checkbox/checkbox.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/code/code.d.ts +11 -0
- package/dist/components/code/code.js +21 -0
- package/dist/components/code/code.js.map +1 -0
- package/dist/components/code/index.d.ts +2 -0
- package/dist/components/details/details.d.ts +22 -0
- package/dist/components/details/details.js +28 -0
- package/dist/components/details/details.js.map +1 -0
- package/dist/components/details/index.d.ts +2 -0
- package/dist/components/dialog/dialog.context.d.ts +4 -0
- package/dist/components/dialog/dialog.context.js +15 -0
- package/dist/components/dialog/dialog.context.js.map +1 -0
- package/dist/components/dialog/dialog.d.ts +67 -0
- package/dist/components/dialog/dialog.js +124 -0
- package/dist/components/dialog/dialog.js.map +1 -0
- package/dist/components/dialog/index.d.ts +3 -0
- package/dist/components/dl/dl.d.ts +18 -0
- package/dist/components/dl/dl.js +48 -0
- package/dist/components/dl/dl.js.map +1 -0
- package/dist/components/dl/index.d.ts +2 -0
- package/dist/components/drawer/drawer.context.d.ts +4 -0
- package/dist/components/drawer/drawer.context.js +15 -0
- package/dist/components/drawer/drawer.context.js.map +1 -0
- package/dist/components/drawer/drawer.d.ts +67 -0
- package/dist/components/drawer/drawer.js +104 -0
- package/dist/components/drawer/drawer.js.map +1 -0
- package/dist/components/drawer/index.d.ts +3 -0
- package/dist/components/fieldset/fieldset.d.ts +9 -0
- package/dist/components/fieldset/fieldset.js +20 -0
- package/dist/components/fieldset/fieldset.js.map +1 -0
- package/dist/components/fieldset/index.d.ts +2 -0
- package/dist/components/heading/heading.d.ts +22 -0
- package/dist/components/heading/heading.js +24 -0
- package/dist/components/heading/heading.js.map +1 -0
- package/dist/components/heading/index.d.ts +2 -0
- package/dist/components/hr/hr.d.ts +11 -0
- package/dist/components/hr/hr.js +19 -0
- package/dist/components/hr/hr.js.map +1 -0
- package/dist/components/hr/index.d.ts +2 -0
- package/dist/components/index.d.ts +66 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/input.d.ts +37 -0
- package/dist/components/input/input.js +47 -0
- package/dist/components/input/input.js.map +1 -0
- package/dist/components/label/index.d.ts +2 -0
- package/dist/components/label/label.d.ts +32 -0
- package/dist/components/label/label.js +54 -0
- package/dist/components/label/label.js.map +1 -0
- package/dist/components/menu/index.d.ts +3 -0
- package/dist/components/menu/menu.context.d.ts +4 -0
- package/dist/components/menu/menu.context.js +15 -0
- package/dist/components/menu/menu.context.js.map +1 -0
- package/dist/components/menu/menu.d.ts +82 -0
- package/dist/components/menu/menu.js +133 -0
- package/dist/components/menu/menu.js.map +1 -0
- package/dist/components/paragraph/index.d.ts +2 -0
- package/dist/components/paragraph/paragraph.d.ts +18 -0
- package/dist/components/paragraph/paragraph.js +21 -0
- package/dist/components/paragraph/paragraph.js.map +1 -0
- package/dist/components/popover/index.d.ts +3 -0
- package/dist/components/popover/popover.context.d.ts +4 -0
- package/dist/components/popover/popover.context.js +15 -0
- package/dist/components/popover/popover.context.js.map +1 -0
- package/dist/components/popover/popover.d.ts +53 -0
- package/dist/components/popover/popover.js +60 -0
- package/dist/components/popover/popover.js.map +1 -0
- package/dist/components/progress/index.d.ts +2 -0
- package/dist/components/progress/progress.d.ts +55 -0
- package/dist/components/progress/progress.js +57 -0
- package/dist/components/progress/progress.js.map +1 -0
- package/dist/components/radio/index.d.ts +2 -0
- package/dist/components/radio/radio.d.ts +27 -0
- package/dist/components/radio/radio.js +57 -0
- package/dist/components/radio/radio.js.map +1 -0
- package/dist/components/radiogroup/index.d.ts +2 -0
- package/dist/components/radiogroup/radiogroup.d.ts +36 -0
- package/dist/components/radiogroup/radiogroup.js +44 -0
- package/dist/components/radiogroup/radiogroup.js.map +1 -0
- package/dist/components/section/index.d.ts +2 -0
- package/dist/components/section/section.d.ts +36 -0
- package/dist/components/section/section.js +26 -0
- package/dist/components/section/section.js.map +1 -0
- package/dist/components/segmented-control/index.d.ts +2 -0
- package/dist/components/segmented-control/segmented-control.context.js +12 -0
- package/dist/components/segmented-control/segmented-control.context.js.map +1 -0
- package/dist/components/segmented-control/segmented-control.d.ts +41 -0
- package/dist/components/segmented-control/segmented-control.js +68 -0
- package/dist/components/segmented-control/segmented-control.js.map +1 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/select.d.ts +31 -0
- package/dist/components/select/select.js +48 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/table.d.ts +53 -0
- package/dist/components/table/table.js +110 -0
- package/dist/components/table/table.js.map +1 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/tabs.context.d.ts +4 -0
- package/dist/components/tabs/tabs.context.js +12 -0
- package/dist/components/tabs/tabs.context.js.map +1 -0
- package/dist/components/tabs/tabs.d.ts +60 -0
- package/dist/components/tabs/tabs.js +158 -0
- package/dist/components/tabs/tabs.js.map +1 -0
- package/dist/components/textarea/index.d.ts +2 -0
- package/dist/components/textarea/textarea.d.ts +37 -0
- package/dist/components/textarea/textarea.js +48 -0
- package/dist/components/textarea/textarea.js.map +1 -0
- package/dist/components/tooltip/index.d.ts +3 -0
- package/dist/components/tooltip/tooltip.context.d.ts +4 -0
- package/dist/components/tooltip/tooltip.context.js +15 -0
- package/dist/components/tooltip/tooltip.context.js.map +1 -0
- package/dist/components/tooltip/tooltip.d.ts +53 -0
- package/dist/components/tooltip/tooltip.js +83 -0
- package/dist/components/tooltip/tooltip.js.map +1 -0
- package/dist/components/visually-hidden/index.d.ts +2 -0
- package/dist/components/visually-hidden/visually-hidden.d.ts +9 -0
- package/dist/components/visually-hidden/visually-hidden.js +21 -0
- package/dist/components/visually-hidden/visually-hidden.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +38 -0
- package/dist/provider/hui-provider.context.d.ts +104 -0
- package/dist/provider/hui-provider.context.js +36 -0
- package/dist/provider/hui-provider.context.js.map +1 -0
- package/dist/provider/hui-provider.d.ts +8 -0
- package/dist/provider/hui-provider.js +17 -0
- package/dist/provider/hui-provider.js.map +1 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/merge-props.js +16 -0
- package/dist/provider/merge-props.js.map +1 -0
- package/dist/types/hui-component.d.ts +8 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/polymorphic.d.ts +13 -0
- package/dist/utils/attributes/normalize-attributes.js +18 -0
- package/dist/utils/attributes/normalize-attributes.js.map +1 -0
- package/package.json +54 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import { HuiPolymorphicProps } from "../../types/polymorphic.js";
|
|
3
|
+
import "../../types/index.js";
|
|
4
|
+
import { SegmentedControlItemSlots, SegmentedControlRootSlots } from "@hebium-ui/core";
|
|
5
|
+
import { ComponentProps, ElementType, ReactElement } from "react";
|
|
6
|
+
//#region src/components/segmented-control/segmented-control.d.ts
|
|
7
|
+
type HtmlUlProps = Omit<ComponentProps<"ul">, "onChange">;
|
|
8
|
+
interface SegmentedControlOwnProps<V extends string> extends HtmlUlProps {
|
|
9
|
+
/**
|
|
10
|
+
* The list of allowed segmented-control values.
|
|
11
|
+
*/
|
|
12
|
+
values: V[];
|
|
13
|
+
/**
|
|
14
|
+
* The currently selected segmented-control value.
|
|
15
|
+
*/
|
|
16
|
+
value?: V | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* The initially selected segmented-control value for uncontrolled component.
|
|
19
|
+
*/
|
|
20
|
+
defaultValue?: V | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Called when the selected segmented-control value changes.
|
|
23
|
+
*/
|
|
24
|
+
onChange?: ((value: V) => void) | undefined;
|
|
25
|
+
}
|
|
26
|
+
export type SegmentedControlProps<V extends string> = HuiComponentProps<SegmentedControlOwnProps<V>, SegmentedControlRootSlots>;
|
|
27
|
+
declare function SegmentedControlRoot<V extends string>(rawProps: SegmentedControlProps<V>): ReactElement;
|
|
28
|
+
interface SegmentedControlItemOwnProps {
|
|
29
|
+
/**
|
|
30
|
+
* The value represented by this control.
|
|
31
|
+
*/
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
export type SegmentedControlItemProps<E extends ElementType = "button"> = HuiPolymorphicProps<E, SegmentedControlItemOwnProps, SegmentedControlItemSlots>;
|
|
35
|
+
declare function Item<E extends ElementType = "button">(rawProps: SegmentedControlItemProps<E>): ReactElement;
|
|
36
|
+
export declare const SegmentedControl: typeof SegmentedControlRoot & {
|
|
37
|
+
Item: typeof Item;
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=segmented-control.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { SegmentedControlContext, useSegmentedControlContext } from "./segmented-control.context.js";
|
|
4
|
+
import { segmentedControl, segmentedControlItemRecipe, segmentedControlRootRecipe } from "@hebium-ui/core";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/components/segmented-control/segmented-control.tsx
|
|
8
|
+
function SegmentedControlRoot(rawProps) {
|
|
9
|
+
const { values, value, defaultValue, onChange, className, style, children, ...restProps } = useHuiProps("SegmentedControl", rawProps);
|
|
10
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(() => value ?? defaultValue ?? values[0]);
|
|
11
|
+
const selectedValue = value ?? uncontrolledValue;
|
|
12
|
+
const recipe = segmentedControlRootRecipe({});
|
|
13
|
+
const cls = useHuiClassNames("SegmentedControl", recipe, { root: className });
|
|
14
|
+
const sls = useHuiStyles("SegmentedControl", { root: style });
|
|
15
|
+
const onSelect = useCallback((nextValue) => {
|
|
16
|
+
if (!values.includes(nextValue)) throw new Error(`[Hebium UI] Unexpected SegmentedControl value: ${nextValue}`);
|
|
17
|
+
const v = nextValue;
|
|
18
|
+
setUncontrolledValue(v);
|
|
19
|
+
onChange?.(v);
|
|
20
|
+
}, [onChange, values]);
|
|
21
|
+
const contextValue = useMemo(() => ({
|
|
22
|
+
selectedValue,
|
|
23
|
+
onSelect
|
|
24
|
+
}), [selectedValue, onSelect]);
|
|
25
|
+
return /* @__PURE__ */ jsx(SegmentedControlContext.Provider, {
|
|
26
|
+
value: contextValue,
|
|
27
|
+
children: /* @__PURE__ */ jsx("ul", {
|
|
28
|
+
className: cls.root,
|
|
29
|
+
style: sls.root,
|
|
30
|
+
...restProps,
|
|
31
|
+
children
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function Item(rawProps) {
|
|
36
|
+
const { as, value, className, style, children, onClick, ...restProps } = useHuiProps("SegmentedControlItem", rawProps);
|
|
37
|
+
const Component = as ?? "button";
|
|
38
|
+
const { selectedValue, onSelect } = useSegmentedControlContext();
|
|
39
|
+
const recipe = segmentedControlItemRecipe({});
|
|
40
|
+
const cls = useHuiClassNames("SegmentedControlItem", recipe, { root: className });
|
|
41
|
+
const sls = useHuiStyles("SegmentedControlItem", { root: style });
|
|
42
|
+
const attrs = normalizeAttributes(segmentedControl.getItemAttributes({
|
|
43
|
+
isButtonElement: typeof as === "undefined",
|
|
44
|
+
selectedValue
|
|
45
|
+
}, value));
|
|
46
|
+
const handleClick = useCallback((e) => {
|
|
47
|
+
onClick?.(e);
|
|
48
|
+
if (e.defaultPrevented) return;
|
|
49
|
+
onSelect(value);
|
|
50
|
+
}, [
|
|
51
|
+
onClick,
|
|
52
|
+
onSelect,
|
|
53
|
+
value
|
|
54
|
+
]);
|
|
55
|
+
return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Component, {
|
|
56
|
+
className: cls.root,
|
|
57
|
+
style: sls.root,
|
|
58
|
+
...attrs,
|
|
59
|
+
onClick: handleClick,
|
|
60
|
+
...restProps,
|
|
61
|
+
children
|
|
62
|
+
}) });
|
|
63
|
+
}
|
|
64
|
+
const SegmentedControl = Object.assign(SegmentedControlRoot, { Item });
|
|
65
|
+
//#endregion
|
|
66
|
+
export { SegmentedControl };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=segmented-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmented-control.js","names":[],"sources":["../../../src/components/segmented-control/segmented-control.tsx"],"sourcesContent":["import {\n segmentedControl,\n segmentedControlItemRecipe,\n type SegmentedControlItemSlots,\n segmentedControlRootRecipe,\n type SegmentedControlRootSlots,\n} from \"@hebium-ui/core\";\nimport {\n type ComponentProps,\n type ElementType,\n type MouseEvent,\n type ReactElement,\n useCallback,\n useMemo,\n useState,\n} from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps, type HuiPolymorphicProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport {\n SegmentedControlContext,\n type SegmentedControlContextValue,\n useSegmentedControlContext,\n} from \"./segmented-control.context\";\n\ntype HtmlUlProps = Omit<ComponentProps<\"ul\">, \"onChange\">;\n\ninterface SegmentedControlOwnProps<V extends string> extends HtmlUlProps {\n /**\n * The list of allowed segmented-control values.\n */\n values: V[];\n /**\n * The currently selected segmented-control value.\n */\n value?: V | undefined;\n /**\n * The initially selected segmented-control value for uncontrolled component.\n */\n defaultValue?: V | undefined;\n /**\n * Called when the selected segmented-control value changes.\n */\n onChange?: ((value: V) => void) | undefined;\n}\nexport type SegmentedControlProps<V extends string> = HuiComponentProps<\n SegmentedControlOwnProps<V>,\n SegmentedControlRootSlots\n>;\n\nfunction SegmentedControlRoot<V extends string>(\n rawProps: SegmentedControlProps<V>,\n): ReactElement {\n const {\n values,\n value,\n defaultValue,\n onChange,\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"SegmentedControl\", rawProps);\n\n const [uncontrolledValue, setUncontrolledValue] = useState<V | undefined>(\n () => value ?? defaultValue ?? values[0],\n );\n const selectedValue = value ?? uncontrolledValue;\n const recipe = segmentedControlRootRecipe({});\n const cls = useHuiClassNames(\"SegmentedControl\", recipe, { root: className });\n const sls = useHuiStyles(\"SegmentedControl\", { root: style });\n\n const onSelect = useCallback(\n (nextValue: string) => {\n if (!(values as string[]).includes(nextValue)) {\n throw new Error(`[Hebium UI] Unexpected SegmentedControl value: ${nextValue}`);\n }\n\n const v = nextValue as V;\n setUncontrolledValue(v);\n onChange?.(v);\n },\n [onChange, values],\n );\n\n const contextValue = useMemo<SegmentedControlContextValue>(\n () => ({\n selectedValue,\n onSelect,\n }),\n [\n selectedValue,\n onSelect,\n ],\n );\n\n return (\n <SegmentedControlContext.Provider value={contextValue}>\n <ul\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </ul>\n </SegmentedControlContext.Provider>\n );\n}\n\ninterface SegmentedControlItemOwnProps {\n /**\n * The value represented by this control.\n */\n value: string;\n}\nexport type SegmentedControlItemProps<E extends ElementType = \"button\"> = HuiPolymorphicProps<\n E,\n SegmentedControlItemOwnProps,\n SegmentedControlItemSlots\n>;\n\nfunction Item<E extends ElementType = \"button\">(rawProps: SegmentedControlItemProps<E>): ReactElement {\n const {\n as,\n value,\n className,\n style,\n children,\n onClick,\n ...restProps\n } = useHuiProps(\"SegmentedControlItem\", rawProps);\n\n const Component = as ?? \"button\";\n\n const { selectedValue, onSelect } = useSegmentedControlContext();\n const recipe = segmentedControlItemRecipe({});\n const cls = useHuiClassNames(\"SegmentedControlItem\", recipe, { root: className });\n const sls = useHuiStyles(\"SegmentedControlItem\", { root: style });\n const attrs = normalizeAttributes(\n segmentedControl.getItemAttributes({\n isButtonElement: typeof as === \"undefined\",\n selectedValue,\n }, value),\n );\n\n const handleClick = useCallback(\n (e: MouseEvent<HTMLButtonElement>): void => {\n onClick?.(e);\n if (e.defaultPrevented) return;\n onSelect(value);\n },\n [onClick, onSelect, value],\n );\n\n return (\n <li>\n <Component\n className={cls.root}\n style={sls.root}\n {...attrs}\n onClick={handleClick}\n {...restProps}\n >\n {children}\n </Component>\n </li>\n );\n}\n\nexport const SegmentedControl = Object.assign(SegmentedControlRoot, {\n Item,\n});\n"],"mappings":";;;;;;;AAkDA,SAAS,qBACP,UACc;CACd,MAAM,EACJ,QACA,OACA,cACA,UACA,WACA,OACA,UACA,GAAG,cACD,YAAY,oBAAoB,QAAQ;CAE5C,MAAM,CAAC,mBAAmB,wBAAwB,eAC1C,SAAS,gBAAgB,OAAO,EACxC;CACA,MAAM,gBAAgB,SAAS;CAC/B,MAAM,SAAS,2BAA2B,CAAC,CAAC;CAC5C,MAAM,MAAM,iBAAiB,oBAAoB,QAAQ,EAAE,MAAM,UAAU,CAAC;CAC5E,MAAM,MAAM,aAAa,oBAAoB,EAAE,MAAM,MAAM,CAAC;CAE5D,MAAM,WAAW,aACd,cAAsB;EACrB,IAAI,CAAE,OAAoB,SAAS,SAAS,GAC1C,MAAM,IAAI,MAAM,kDAAkD,WAAW;EAG/E,MAAM,IAAI;EACV,qBAAqB,CAAC;EACtB,WAAW,CAAC;CACd,GACA,CAAC,UAAU,MAAM,CACnB;CAEA,MAAM,eAAe,eACZ;EACL;EACA;CACF,IACA,CACE,eACA,QACF,CACF;CAEA,OACE,oBAAC,wBAAwB,UAAzB;EAAkC,OAAO;EACvC,UAAA,oBAAC,MAAD;GACE,WAAW,IAAI;GACf,OAAO,IAAI;GACX,GAAI;GAEH;EACC,CAAA;CAC4B,CAAA;AAEtC;AAcA,SAAS,KAAuC,UAAsD;CACpG,MAAM,EACJ,IACA,OACA,WACA,OACA,UACA,SACA,GAAG,cACD,YAAY,wBAAwB,QAAQ;CAEhD,MAAM,YAAY,MAAM;CAExB,MAAM,EAAE,eAAe,aAAa,2BAA2B;CAC/D,MAAM,SAAS,2BAA2B,CAAC,CAAC;CAC5C,MAAM,MAAM,iBAAiB,wBAAwB,QAAQ,EAAE,MAAM,UAAU,CAAC;CAChF,MAAM,MAAM,aAAa,wBAAwB,EAAE,MAAM,MAAM,CAAC;CAChE,MAAM,QAAQ,oBACZ,iBAAiB,kBAAkB;EACjC,iBAAiB,OAAO,OAAO;EAC/B;CACF,GAAG,KAAK,CACV;CAEA,MAAM,cAAc,aACjB,MAA2C;EAC1C,UAAU,CAAC;EACX,IAAI,EAAE,kBAAkB;EACxB,SAAS,KAAK;CAChB,GACA;EAAC;EAAS;EAAU;CAAK,CAC3B;CAEA,OACE,oBAAC,MAAD,EAAA,UACE,oBAAC,WAAD;EACE,WAAW,IAAI;EACf,OAAO,IAAI;EACX,GAAI;EACJ,SAAS;EACT,GAAI;EAEH;CACQ,CAAA,EACT,CAAA;AAER;AAEA,MAAa,mBAAmB,OAAO,OAAO,sBAAsB,EAClE,KACF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { LabelProps } from "../label/label.js";
|
|
4
|
+
import "../label/index.js";
|
|
5
|
+
import { SelectSlots } from "@hebium-ui/core";
|
|
6
|
+
import { ComponentProps, ReactElement, ReactNode } from "react";
|
|
7
|
+
//#region src/components/select/select.d.ts
|
|
8
|
+
type HtmlSelectProps = ComponentProps<"select">;
|
|
9
|
+
interface SelectOwnProps extends HtmlSelectProps {
|
|
10
|
+
/**
|
|
11
|
+
* The label displayed above the select.
|
|
12
|
+
*/
|
|
13
|
+
label?: ReactNode | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Additional props passed to the internal label component.
|
|
16
|
+
*/
|
|
17
|
+
labelProps?: LabelProps | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The help text displayed below the label.
|
|
20
|
+
*/
|
|
21
|
+
description?: ReactNode | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The validation error message displayed below the label.
|
|
24
|
+
*/
|
|
25
|
+
error?: ReactNode | undefined;
|
|
26
|
+
}
|
|
27
|
+
export type SelectProps = HuiComponentProps<SelectOwnProps, SelectSlots>;
|
|
28
|
+
export declare function Select(rawProps: SelectProps): ReactElement;
|
|
29
|
+
//#endregion
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { Label } from "../label/label.js";
|
|
4
|
+
import { inputControl, selectRecipe, toBool, toStrbool } from "@hebium-ui/core";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
//#region src/components/select/select.tsx
|
|
8
|
+
function Select(rawProps) {
|
|
9
|
+
const { id, classNames, styles, label, description, error, labelProps, ...restProps } = useHuiProps("Select", rawProps);
|
|
10
|
+
const tmpId = useId();
|
|
11
|
+
const inputState = {
|
|
12
|
+
id: id || tmpId,
|
|
13
|
+
invalid: !!error,
|
|
14
|
+
required: restProps.required ?? toBool(restProps["aria-required"]),
|
|
15
|
+
disabled: toBool(restProps.disabled) || toBool(restProps["aria-disabled"])
|
|
16
|
+
};
|
|
17
|
+
const recipe = selectRecipe({ error: toStrbool(inputState.invalid) });
|
|
18
|
+
const cls = useHuiClassNames("Select", recipe, classNames);
|
|
19
|
+
const sls = useHuiStyles("Select", styles);
|
|
20
|
+
const hasLabel = !!label || !!description || !!error;
|
|
21
|
+
const controlAttrs = normalizeAttributes(inputControl.getControlAttributes(inputState));
|
|
22
|
+
const labelAttrs = normalizeAttributes(inputControl.getLabelAttributes(inputState));
|
|
23
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
24
|
+
"data-disabled": inputState.disabled,
|
|
25
|
+
className: cls.root,
|
|
26
|
+
style: sls.root,
|
|
27
|
+
children: [hasLabel && /* @__PURE__ */ jsx(Label, {
|
|
28
|
+
...labelAttrs,
|
|
29
|
+
description,
|
|
30
|
+
error,
|
|
31
|
+
...labelProps,
|
|
32
|
+
children: label
|
|
33
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: cls.wrapper,
|
|
35
|
+
style: sls.wrapper,
|
|
36
|
+
children: /* @__PURE__ */ jsx("select", {
|
|
37
|
+
className: cls.select,
|
|
38
|
+
style: sls.select,
|
|
39
|
+
...controlAttrs,
|
|
40
|
+
...restProps
|
|
41
|
+
})
|
|
42
|
+
})]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { Select };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","names":[],"sources":["../../../src/components/select/select.tsx"],"sourcesContent":["import { inputControl, selectRecipe, type SelectSlots, toBool, toStrbool } from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement, type ReactNode, useId } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\nimport { normalizeAttributes } from \"~/utils\";\nimport { Label, type LabelProps } from \"../label\";\n\ntype HtmlSelectProps = ComponentProps<\"select\">;\n\ninterface SelectOwnProps extends HtmlSelectProps {\n /**\n * The label displayed above the select.\n */\n label?: ReactNode | undefined;\n /**\n * Additional props passed to the internal label component.\n */\n labelProps?: LabelProps | undefined;\n /**\n * The help text displayed below the label.\n */\n description?: ReactNode | undefined;\n /**\n * The validation error message displayed below the label.\n */\n error?: ReactNode | undefined;\n}\n\nexport type SelectProps = HuiComponentProps<\n SelectOwnProps,\n SelectSlots\n>;\n\nexport function Select(rawProps: SelectProps): ReactElement {\n const {\n id,\n classNames,\n styles,\n label,\n description,\n error,\n labelProps,\n ...restProps\n } = useHuiProps(\"Select\", rawProps);\n\n const tmpId = useId();\n\n const inputState = {\n id: id || tmpId,\n invalid: !!error,\n required: restProps.required ?? toBool(restProps[\"aria-required\"]),\n disabled: toBool(restProps.disabled) || toBool(restProps[\"aria-disabled\"]),\n };\n const recipe = selectRecipe({\n error: toStrbool(inputState.invalid),\n });\n const cls = useHuiClassNames(\"Select\", recipe, classNames);\n const sls = useHuiStyles(\"Select\", styles);\n const hasLabel = !!label || !!description || !!error;\n const controlAttrs = normalizeAttributes(inputControl.getControlAttributes(inputState));\n const labelAttrs = normalizeAttributes(inputControl.getLabelAttributes(inputState));\n\n return (\n <div\n data-disabled={inputState.disabled}\n className={cls.root}\n style={sls.root}\n >\n {hasLabel\n && (\n <Label\n {...labelAttrs}\n description={description}\n error={error}\n {...labelProps}\n >\n {label}\n </Label>\n )}\n <div className={cls.wrapper} style={sls.wrapper}>\n <select\n className={cls.select}\n style={sls.select}\n {...controlAttrs}\n {...restProps}\n />\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAiCA,SAAgB,OAAO,UAAqC;CAC1D,MAAM,EACJ,IACA,YACA,QACA,OACA,aACA,OACA,YACA,GAAG,cACD,YAAY,UAAU,QAAQ;CAElC,MAAM,QAAQ,MAAM;CAEpB,MAAM,aAAa;EACjB,IAAI,MAAM;EACV,SAAS,CAAC,CAAC;EACX,UAAU,UAAU,YAAY,OAAO,UAAU,gBAAgB;EACjE,UAAU,OAAO,UAAU,QAAQ,KAAK,OAAO,UAAU,gBAAgB;CAC3E;CACA,MAAM,SAAS,aAAa,EAC1B,OAAO,UAAU,WAAW,OAAO,EACrC,CAAC;CACD,MAAM,MAAM,iBAAiB,UAAU,QAAQ,UAAU;CACzD,MAAM,MAAM,aAAa,UAAU,MAAM;CACzC,MAAM,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;CAC/C,MAAM,eAAe,oBAAoB,aAAa,qBAAqB,UAAU,CAAC;CACtF,MAAM,aAAa,oBAAoB,aAAa,mBAAmB,UAAU,CAAC;CAElF,OACE,qBAAC,OAAD;EACE,iBAAe,WAAW;EAC1B,WAAW,IAAI;EACf,OAAO,IAAI;EAHb,UAAA,CAKG,YAEG,oBAAC,OAAD;GACE,GAAI;GACS;GACN;GACP,GAAI;GAEH,UAAA;EACI,CAAA,GAEX,oBAAC,OAAD;GAAK,WAAW,IAAI;GAAS,OAAO,IAAI;GACtC,UAAA,oBAAC,UAAD;IACE,WAAW,IAAI;IACf,OAAO,IAAI;IACX,GAAI;IACJ,GAAI;GACL,CAAA;EACE,CAAA,CACF;;AAET"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { HuiComponentProps } from "../../types/hui-component.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { CaptionSlots, CaptionVariants, TableSlots, TableVariants, TdSlots, ThSlots, TrSlots, TrVariants } from "@hebium-ui/core";
|
|
4
|
+
import { ComponentProps, ReactElement } from "react";
|
|
5
|
+
//#region src/components/table/table.d.ts
|
|
6
|
+
interface TableOwnProps extends Omit<ComponentProps<"table">, "border"> {
|
|
7
|
+
/**
|
|
8
|
+
* The border style of the table.
|
|
9
|
+
*/
|
|
10
|
+
border?: TableVariants["border"] | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface TableProps extends HuiComponentProps<TableOwnProps, TableSlots> {}
|
|
13
|
+
declare function TableRoot(rawProps: TableProps): ReactElement;
|
|
14
|
+
interface CaptionOwnProps extends ComponentProps<"caption"> {
|
|
15
|
+
/**
|
|
16
|
+
* The side on which the caption is displayed.
|
|
17
|
+
*/
|
|
18
|
+
side?: CaptionVariants["side"] | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface CaptionProps extends HuiComponentProps<CaptionOwnProps, CaptionSlots> {}
|
|
21
|
+
declare function Caption(rawProps: CaptionProps): ReactElement;
|
|
22
|
+
export type TheadProps = ComponentProps<"thead">;
|
|
23
|
+
declare function Thead(rawProps: TheadProps): ReactElement;
|
|
24
|
+
export type TbodyProps = ComponentProps<"tbody">;
|
|
25
|
+
declare function Tbody(rawProps: TbodyProps): ReactElement;
|
|
26
|
+
export type TfootProps = ComponentProps<"tfoot">;
|
|
27
|
+
declare function Tfoot(rawProps: TfootProps): ReactElement;
|
|
28
|
+
interface TrOwnProps extends ComponentProps<"tr"> {
|
|
29
|
+
/**
|
|
30
|
+
* The border style of the table row.
|
|
31
|
+
*
|
|
32
|
+
* @default "block-end"
|
|
33
|
+
*/
|
|
34
|
+
border?: TrVariants["border"] | undefined;
|
|
35
|
+
}
|
|
36
|
+
export interface TrProps extends HuiComponentProps<TrOwnProps, TrSlots> {}
|
|
37
|
+
declare function Tr(rawProps: TrProps): ReactElement;
|
|
38
|
+
export interface ThProps extends HuiComponentProps<ComponentProps<"th">, ThSlots> {}
|
|
39
|
+
declare function Th(rawProps: ThProps): ReactElement;
|
|
40
|
+
export interface TdProps extends HuiComponentProps<ComponentProps<"td">, TdSlots> {}
|
|
41
|
+
declare function Td(rawProps: TdProps): ReactElement;
|
|
42
|
+
export declare const Table: typeof TableRoot & {
|
|
43
|
+
Caption: typeof Caption;
|
|
44
|
+
Thead: typeof Thead;
|
|
45
|
+
Tbody: typeof Tbody;
|
|
46
|
+
Tfoot: typeof Tfoot;
|
|
47
|
+
Tr: typeof Tr;
|
|
48
|
+
Th: typeof Th;
|
|
49
|
+
Td: typeof Td;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { captionRecipe, tableRecipe, tdRecipe, thRecipe, trRecipe } from "@hebium-ui/core";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/components/table/table.tsx
|
|
5
|
+
function TableRoot(rawProps) {
|
|
6
|
+
const { border, className, style, children, ...restProps } = useHuiProps("Table", rawProps);
|
|
7
|
+
const recipe = tableRecipe({ border });
|
|
8
|
+
const cls = useHuiClassNames("Table", recipe, { root: className });
|
|
9
|
+
const sls = useHuiStyles("Table", { root: style });
|
|
10
|
+
return /* @__PURE__ */ jsx("table", {
|
|
11
|
+
className: cls.root,
|
|
12
|
+
style: sls.root,
|
|
13
|
+
...restProps,
|
|
14
|
+
children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function Caption(rawProps) {
|
|
18
|
+
const { side, className, style, children, ...restProps } = useHuiProps("TableCaption", rawProps);
|
|
19
|
+
const recipe = captionRecipe({ side });
|
|
20
|
+
const cls = useHuiClassNames("TableCaption", recipe, { root: className });
|
|
21
|
+
const sls = useHuiStyles("TableCaption", { root: style });
|
|
22
|
+
return /* @__PURE__ */ jsx("caption", {
|
|
23
|
+
className: cls.root,
|
|
24
|
+
style: sls.root,
|
|
25
|
+
...restProps,
|
|
26
|
+
children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function Thead(rawProps) {
|
|
30
|
+
const { className, style, children, ...restProps } = useHuiProps("TableThead", rawProps);
|
|
31
|
+
const cls = useHuiClassNames("TableThead", { root: "" }, { root: className });
|
|
32
|
+
const sls = useHuiStyles("TableThead", { root: style });
|
|
33
|
+
return /* @__PURE__ */ jsx("thead", {
|
|
34
|
+
className: cls.root,
|
|
35
|
+
style: sls.root,
|
|
36
|
+
...restProps,
|
|
37
|
+
children
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function Tbody(rawProps) {
|
|
41
|
+
const { className, style, children, ...restProps } = useHuiProps("TableTbody", rawProps);
|
|
42
|
+
const cls = useHuiClassNames("TableTbody", { root: "" }, { root: className });
|
|
43
|
+
const sls = useHuiStyles("TableTbody", { root: style });
|
|
44
|
+
return /* @__PURE__ */ jsx("tbody", {
|
|
45
|
+
className: cls.root,
|
|
46
|
+
style: sls.root,
|
|
47
|
+
...restProps,
|
|
48
|
+
children
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function Tfoot(rawProps) {
|
|
52
|
+
const { className, style, children, ...restProps } = useHuiProps("TableTfoot", rawProps);
|
|
53
|
+
const cls = useHuiClassNames("TableTfoot", { root: "" }, { root: className });
|
|
54
|
+
const sls = useHuiStyles("TableTfoot", { root: style });
|
|
55
|
+
return /* @__PURE__ */ jsx("tfoot", {
|
|
56
|
+
className: cls.root,
|
|
57
|
+
style: sls.root,
|
|
58
|
+
...restProps,
|
|
59
|
+
children
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function Tr(rawProps) {
|
|
63
|
+
const { border, className, style, children, ...restProps } = useHuiProps("TableTr", rawProps);
|
|
64
|
+
const recipe = trRecipe({ border });
|
|
65
|
+
const cls = useHuiClassNames("TableTr", recipe, { root: className });
|
|
66
|
+
const sls = useHuiStyles("TableTr", { root: style });
|
|
67
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
68
|
+
className: cls.root,
|
|
69
|
+
style: sls.root,
|
|
70
|
+
...restProps,
|
|
71
|
+
children
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function Th(rawProps) {
|
|
75
|
+
const { className, style, children, ...restProps } = useHuiProps("TableTh", rawProps);
|
|
76
|
+
const recipe = thRecipe({});
|
|
77
|
+
const cls = useHuiClassNames("TableTh", recipe, { root: className });
|
|
78
|
+
const sls = useHuiStyles("TableTh", { root: style });
|
|
79
|
+
return /* @__PURE__ */ jsx("th", {
|
|
80
|
+
className: cls.root,
|
|
81
|
+
style: sls.root,
|
|
82
|
+
...restProps,
|
|
83
|
+
children
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function Td(rawProps) {
|
|
87
|
+
const { className, style, children, ...restProps } = useHuiProps("TableTd", rawProps);
|
|
88
|
+
const recipe = tdRecipe({});
|
|
89
|
+
const cls = useHuiClassNames("TableTd", recipe, { root: className });
|
|
90
|
+
const sls = useHuiStyles("TableTd", { root: style });
|
|
91
|
+
return /* @__PURE__ */ jsx("td", {
|
|
92
|
+
className: cls.root,
|
|
93
|
+
style: sls.root,
|
|
94
|
+
...restProps,
|
|
95
|
+
children
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const Table = Object.assign(TableRoot, {
|
|
99
|
+
Caption,
|
|
100
|
+
Thead,
|
|
101
|
+
Tbody,
|
|
102
|
+
Tfoot,
|
|
103
|
+
Tr,
|
|
104
|
+
Th,
|
|
105
|
+
Td
|
|
106
|
+
});
|
|
107
|
+
//#endregion
|
|
108
|
+
export { Table };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","names":[],"sources":["../../../src/components/table/table.tsx"],"sourcesContent":["import {\n captionRecipe,\n type CaptionSlots,\n type CaptionVariants,\n tableRecipe,\n type TableSlots,\n type TableVariants,\n tdRecipe,\n type TdSlots,\n thRecipe,\n type ThSlots,\n trRecipe,\n type TrSlots,\n type TrVariants,\n} from \"@hebium-ui/core\";\nimport { type ComponentProps, type ReactElement } from \"react\";\nimport { useHuiClassNames, useHuiProps, useHuiStyles } from \"~/provider\";\nimport { type HuiComponentProps } from \"~/types\";\n\ninterface TableOwnProps extends Omit<ComponentProps<\"table\">, \"border\"> {\n /**\n * The border style of the table.\n */\n border?: TableVariants[\"border\"] | undefined;\n}\nexport interface TableProps extends HuiComponentProps<TableOwnProps, TableSlots> {}\n\nfunction TableRoot(rawProps: TableProps): ReactElement {\n const {\n border,\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"Table\", rawProps);\n\n const recipe = tableRecipe({ border });\n const cls = useHuiClassNames(\"Table\", recipe, { root: className });\n const sls = useHuiStyles(\"Table\", { root: style });\n\n return (\n <table\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </table>\n );\n}\n\ninterface CaptionOwnProps extends ComponentProps<\"caption\"> {\n /**\n * The side on which the caption is displayed.\n */\n side?: CaptionVariants[\"side\"] | undefined;\n}\nexport interface CaptionProps extends HuiComponentProps<CaptionOwnProps, CaptionSlots> {}\n\nfunction Caption(rawProps: CaptionProps): ReactElement {\n const {\n side,\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableCaption\", rawProps);\n\n const recipe = captionRecipe({ side });\n const cls = useHuiClassNames(\"TableCaption\", recipe, { root: className });\n const sls = useHuiStyles(\"TableCaption\", { root: style });\n\n return (\n <caption\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </caption>\n );\n}\n\nexport type TheadProps = ComponentProps<\"thead\">;\n\nfunction Thead(rawProps: TheadProps): ReactElement {\n const {\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableThead\", rawProps);\n\n const cls = useHuiClassNames(\"TableThead\", { root: \"\" }, { root: className });\n const sls = useHuiStyles(\"TableThead\", { root: style });\n\n return (\n <thead\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </thead>\n );\n}\n\nexport type TbodyProps = ComponentProps<\"tbody\">;\n\nfunction Tbody(rawProps: TbodyProps): ReactElement {\n const {\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableTbody\", rawProps);\n\n const cls = useHuiClassNames(\"TableTbody\", { root: \"\" }, { root: className });\n const sls = useHuiStyles(\"TableTbody\", { root: style });\n\n return (\n <tbody\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </tbody>\n );\n}\n\nexport type TfootProps = ComponentProps<\"tfoot\">;\n\nfunction Tfoot(rawProps: TfootProps): ReactElement {\n const {\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableTfoot\", rawProps);\n\n const cls = useHuiClassNames(\"TableTfoot\", { root: \"\" }, { root: className });\n const sls = useHuiStyles(\"TableTfoot\", { root: style });\n\n return (\n <tfoot\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </tfoot>\n );\n}\n\ninterface TrOwnProps extends ComponentProps<\"tr\"> {\n /**\n * The border style of the table row.\n *\n * @default \"block-end\"\n */\n border?: TrVariants[\"border\"] | undefined;\n}\nexport interface TrProps extends HuiComponentProps<TrOwnProps, TrSlots> {}\n\nfunction Tr(rawProps: TrProps): ReactElement {\n const {\n border,\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableTr\", rawProps);\n\n const recipe = trRecipe({ border });\n const cls = useHuiClassNames(\"TableTr\", recipe, { root: className });\n const sls = useHuiStyles(\"TableTr\", { root: style });\n\n return (\n <tr\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </tr>\n );\n}\n\nexport interface ThProps extends HuiComponentProps<ComponentProps<\"th\">, ThSlots> {}\n\nfunction Th(rawProps: ThProps): ReactElement {\n const {\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableTh\", rawProps);\n\n const recipe = thRecipe({});\n const cls = useHuiClassNames(\"TableTh\", recipe, { root: className });\n const sls = useHuiStyles(\"TableTh\", { root: style });\n\n return (\n <th\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </th>\n );\n}\n\nexport interface TdProps extends HuiComponentProps<ComponentProps<\"td\">, TdSlots> {}\n\nfunction Td(rawProps: TdProps): ReactElement {\n const {\n className,\n style,\n children,\n ...restProps\n } = useHuiProps(\"TableTd\", rawProps);\n\n const recipe = tdRecipe({});\n const cls = useHuiClassNames(\"TableTd\", recipe, { root: className });\n const sls = useHuiStyles(\"TableTd\", { root: style });\n\n return (\n <td\n className={cls.root}\n style={sls.root}\n {...restProps}\n >\n {children}\n </td>\n );\n}\n\nexport const Table = Object.assign(TableRoot, {\n Caption,\n Thead,\n Tbody,\n Tfoot,\n Tr,\n Th,\n Td,\n});\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
//#region src/components/tabs/tabs.context.ts
|
|
3
|
+
const TabsContext = createContext(null);
|
|
4
|
+
function useTabsContext() {
|
|
5
|
+
const context = useContext(TabsContext);
|
|
6
|
+
if (!context) throw new Error("[Hebium UI] Tabs compound components must be used within <Tabs>");
|
|
7
|
+
return context;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { TabsContext, useTabsContext };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=tabs.context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.context.js","names":[],"sources":["../../../src/components/tabs/tabs.context.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\n\nexport type ActivationMode = \"manual\" | \"auto\";\n\nexport interface TabsContextValue {\n rootId: string;\n selectedValue: string | undefined;\n onSelect: (value: string) => void;\n activation: ActivationMode;\n}\n\nexport const TabsContext = createContext<TabsContextValue | null>(null);\n\nexport function useTabsContext(): TabsContextValue {\n const context = useContext(TabsContext);\n if (!context) {\n throw new Error(\"[Hebium UI] Tabs compound components must be used within <Tabs>\");\n }\n return context;\n}\n"],"mappings":";;AAWA,MAAa,cAAc,cAAuC,IAAI;AAEtE,SAAgB,iBAAmC;CACjD,MAAM,UAAU,WAAW,WAAW;CACtC,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,iEAAiE;CAEnF,OAAO;AACT"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { HuiPolymorphicProps } from "../../types/polymorphic.js";
|
|
2
|
+
import "../../types/index.js";
|
|
3
|
+
import { ActivationMode } from "./tabs.context.js";
|
|
4
|
+
import { TabSlots, TablistSlots, TabpanelSlots, TabrootSlots } from "@hebium-ui/core";
|
|
5
|
+
import { ElementType, ReactElement } from "react";
|
|
6
|
+
//#region src/components/tabs/tabs.d.ts
|
|
7
|
+
interface TabsOwnProps<V extends string> {
|
|
8
|
+
/**
|
|
9
|
+
* The list of allowed tab values.
|
|
10
|
+
*/
|
|
11
|
+
values: V[];
|
|
12
|
+
/**
|
|
13
|
+
* The currently selected tab value.
|
|
14
|
+
*/
|
|
15
|
+
value?: V | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The initially selected tab value for uncontrolled tabs.
|
|
18
|
+
*/
|
|
19
|
+
defaultValue?: V | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Called when the selected tab value changes.
|
|
22
|
+
*/
|
|
23
|
+
onChange?: ((value: V) => void) | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The activation mode used when focus moves between tabs.
|
|
26
|
+
*
|
|
27
|
+
* @default "manual"
|
|
28
|
+
* @see {@link https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_selection_follows_focus | WAI-ARIA APG: Deciding When to Make Selection Automatically Follow Focus}
|
|
29
|
+
*/
|
|
30
|
+
activation?: ActivationMode;
|
|
31
|
+
}
|
|
32
|
+
export type TabsProps<V extends string, E extends ElementType = "div"> = HuiPolymorphicProps<E, TabsOwnProps<V>, TabrootSlots>;
|
|
33
|
+
declare function TabsRoot<V extends string, E extends ElementType = "div">(rawProps: TabsProps<V, E>): ReactElement;
|
|
34
|
+
interface TabsListOwnProps {}
|
|
35
|
+
export type TabsListProps<E extends ElementType = "div"> = HuiPolymorphicProps<E, TabsListOwnProps, TablistSlots>;
|
|
36
|
+
declare function List<E extends ElementType = "div">(rawProps: TabsListProps<E>): ReactElement;
|
|
37
|
+
interface TabsTabOwnProps {
|
|
38
|
+
/**
|
|
39
|
+
* The value represented by this tab.
|
|
40
|
+
*/
|
|
41
|
+
value: string;
|
|
42
|
+
}
|
|
43
|
+
export type TabsTabProps<E extends ElementType = "button"> = HuiPolymorphicProps<E, TabsTabOwnProps, TabSlots>;
|
|
44
|
+
declare function Tab<E extends ElementType = "button">(rawProps: TabsTabProps<E>): ReactElement;
|
|
45
|
+
interface TabsPanelOwnProps {
|
|
46
|
+
/**
|
|
47
|
+
* The tab value associated with this panel.
|
|
48
|
+
*/
|
|
49
|
+
value: string;
|
|
50
|
+
}
|
|
51
|
+
export type TabsPanelProps<E extends ElementType = "div"> = HuiPolymorphicProps<E, TabsPanelOwnProps, TabpanelSlots>;
|
|
52
|
+
declare function Panel<E extends ElementType = "div">(rawProps: TabsPanelProps<E>): ReactElement;
|
|
53
|
+
export declare const Tabs: typeof TabsRoot & {
|
|
54
|
+
List: typeof List;
|
|
55
|
+
Tab: typeof Tab;
|
|
56
|
+
Panel: typeof Panel;
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { useHuiClassNames, useHuiProps, useHuiStyles } from "../../provider/hui-provider.context.js";
|
|
2
|
+
import { normalizeAttributes } from "../../utils/attributes/normalize-attributes.js";
|
|
3
|
+
import { TabsContext, useTabsContext } from "./tabs.context.js";
|
|
4
|
+
import { tabRecipe, tablistRecipe, tabpanelRecipe, tabrootRecipe, tabsControl } from "@hebium-ui/core";
|
|
5
|
+
import { useCallback, useId, useMemo, useState } from "react";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/components/tabs/tabs.tsx
|
|
8
|
+
function TabsRoot(rawProps) {
|
|
9
|
+
const { as, id, values, value, defaultValue, onChange, className, style, children, activation = "manual", ...restProps } = useHuiProps("Tabs", rawProps);
|
|
10
|
+
const Component = as ?? "div";
|
|
11
|
+
const tmpId = useId();
|
|
12
|
+
const rootId = id || tmpId;
|
|
13
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(() => value ?? defaultValue ?? values[0]);
|
|
14
|
+
const selectedValue = value ?? uncontrolledValue;
|
|
15
|
+
const recipe = tabrootRecipe({});
|
|
16
|
+
const cls = useHuiClassNames("Tabs", recipe, { root: className });
|
|
17
|
+
const sls = useHuiStyles("Tabs", { root: style });
|
|
18
|
+
const onSelect = useCallback((nextValue) => {
|
|
19
|
+
if (!values.includes(nextValue)) throw new Error(`[Hebium UI] Unexpected Tab value: ${nextValue}`);
|
|
20
|
+
const v = nextValue;
|
|
21
|
+
setUncontrolledValue(v);
|
|
22
|
+
onChange?.(v);
|
|
23
|
+
}, [onChange, values]);
|
|
24
|
+
const contextValue = useMemo(() => ({
|
|
25
|
+
rootId,
|
|
26
|
+
selectedValue,
|
|
27
|
+
onSelect,
|
|
28
|
+
activation
|
|
29
|
+
}), [
|
|
30
|
+
rootId,
|
|
31
|
+
selectedValue,
|
|
32
|
+
onSelect,
|
|
33
|
+
activation
|
|
34
|
+
]);
|
|
35
|
+
const attrs = normalizeAttributes(tabsControl.getRootAttributes({
|
|
36
|
+
rootId,
|
|
37
|
+
selectedValue
|
|
38
|
+
}));
|
|
39
|
+
return /* @__PURE__ */ jsx(TabsContext.Provider, {
|
|
40
|
+
value: contextValue,
|
|
41
|
+
children: /* @__PURE__ */ jsx(Component, {
|
|
42
|
+
className: cls.root,
|
|
43
|
+
style: sls.root,
|
|
44
|
+
...attrs,
|
|
45
|
+
...restProps,
|
|
46
|
+
children
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function List(rawProps) {
|
|
51
|
+
const { as, className, style, children, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, ...restProps } = useHuiProps("TabsList", rawProps);
|
|
52
|
+
const Component = as ?? "div";
|
|
53
|
+
const recipe = tablistRecipe({});
|
|
54
|
+
const cls = useHuiClassNames("TabsList", recipe, { root: className });
|
|
55
|
+
const sls = useHuiStyles("TabsList", { root: style });
|
|
56
|
+
const { rootId, selectedValue } = useTabsContext();
|
|
57
|
+
const attrs = normalizeAttributes(tabsControl.getListAttributes({
|
|
58
|
+
rootId,
|
|
59
|
+
selectedValue
|
|
60
|
+
}, {
|
|
61
|
+
ariaLabel,
|
|
62
|
+
ariaLabelledBy
|
|
63
|
+
}));
|
|
64
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
65
|
+
className: cls.root,
|
|
66
|
+
style: sls.root,
|
|
67
|
+
...attrs,
|
|
68
|
+
...restProps,
|
|
69
|
+
children
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function Tab(rawProps) {
|
|
73
|
+
const { as, value, className, style, children, onClick, onKeyDown, onFocus, ...restProps } = useHuiProps("TabsTab", rawProps);
|
|
74
|
+
const Component = as ?? "button";
|
|
75
|
+
const { rootId, selectedValue, onSelect, activation } = useTabsContext();
|
|
76
|
+
const recipe = tabRecipe({});
|
|
77
|
+
const cls = useHuiClassNames("TabsTab", recipe, { root: className });
|
|
78
|
+
const sls = useHuiStyles("TabsTab", { root: style });
|
|
79
|
+
const attrs = normalizeAttributes(tabsControl.getTabAttributes({
|
|
80
|
+
rootId,
|
|
81
|
+
selectedValue
|
|
82
|
+
}, value, { isButtonElement: as === void 0 }));
|
|
83
|
+
const handleClick = useCallback((e) => {
|
|
84
|
+
onClick?.(e);
|
|
85
|
+
if (e.defaultPrevented) return;
|
|
86
|
+
onSelect(value);
|
|
87
|
+
}, [
|
|
88
|
+
onClick,
|
|
89
|
+
onSelect,
|
|
90
|
+
value
|
|
91
|
+
]);
|
|
92
|
+
const handleKeyDown = useCallback((e) => {
|
|
93
|
+
onKeyDown?.(e);
|
|
94
|
+
if (e.defaultPrevented) return;
|
|
95
|
+
switch (tabsControl.handleTabKeydown(e.nativeEvent)) {
|
|
96
|
+
case "activate":
|
|
97
|
+
onSelect(value);
|
|
98
|
+
return;
|
|
99
|
+
case "focus-move":
|
|
100
|
+
tabsControl.moveFocus(e.nativeEvent, rootId);
|
|
101
|
+
return;
|
|
102
|
+
case "none": return;
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
onKeyDown,
|
|
106
|
+
onSelect,
|
|
107
|
+
rootId,
|
|
108
|
+
value
|
|
109
|
+
]);
|
|
110
|
+
const handleFocus = useCallback((e) => {
|
|
111
|
+
onFocus?.(e);
|
|
112
|
+
if (e.defaultPrevented) return;
|
|
113
|
+
if (activation === "auto") onSelect(value);
|
|
114
|
+
}, [
|
|
115
|
+
onFocus,
|
|
116
|
+
onSelect,
|
|
117
|
+
activation,
|
|
118
|
+
value
|
|
119
|
+
]);
|
|
120
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
121
|
+
className: cls.root,
|
|
122
|
+
style: sls.root,
|
|
123
|
+
...attrs,
|
|
124
|
+
onClick: handleClick,
|
|
125
|
+
onKeyDown: handleKeyDown,
|
|
126
|
+
onFocus: handleFocus,
|
|
127
|
+
...restProps,
|
|
128
|
+
children
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
function Panel(rawProps) {
|
|
132
|
+
const { as, value, className, style, children, ...restProps } = useHuiProps("TabsPanel", rawProps);
|
|
133
|
+
const Component = as ?? "div";
|
|
134
|
+
const { rootId, selectedValue } = useTabsContext();
|
|
135
|
+
const recipe = tabpanelRecipe({});
|
|
136
|
+
const cls = useHuiClassNames("TabsPanel", recipe, { root: className });
|
|
137
|
+
const sls = useHuiStyles("TabsPanel", { root: style });
|
|
138
|
+
const attrs = normalizeAttributes(tabsControl.getPanelAttributes({
|
|
139
|
+
rootId,
|
|
140
|
+
selectedValue
|
|
141
|
+
}, value));
|
|
142
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
143
|
+
className: cls.root,
|
|
144
|
+
style: sls.root,
|
|
145
|
+
...attrs,
|
|
146
|
+
...restProps,
|
|
147
|
+
children
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const Tabs = Object.assign(TabsRoot, {
|
|
151
|
+
List,
|
|
152
|
+
Tab,
|
|
153
|
+
Panel
|
|
154
|
+
});
|
|
155
|
+
//#endregion
|
|
156
|
+
export { Tabs };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=tabs.js.map
|