@gbgr/react 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 gbgr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @gbgr/react
2
+
3
+ This package contains React components and hooks for the GBGR Design System.
4
+
5
+ ## Development Guidelines
6
+
7
+ ### Do not import Token JSON directly
8
+
9
+ Components and hooks in this package should not directly import `tokens.json` or any derived JSON token files. Instead, consume design tokens through CSS variables (e.g., `var(--gbgr-color-primary)`) to maintain consistency and leverage the theming capabilities provided by the `@gbgr/tokens` package.
10
+
11
+ ## Usage
12
+
13
+ ### Button
14
+
15
+ Make sure token CSS is loaded (e.g. via `@gbgr/css`), then:
16
+
17
+ ```tsx
18
+ import { Button } from "@gbgr/react";
19
+ import "@gbgr/react/button.css";
20
+
21
+ export function Example() {
22
+ return <Button tone="primary">Save</Button>;
23
+ }
24
+ ```
@@ -0,0 +1,27 @@
1
+ import { type UseAccordionProps } from "@gbgr/react-headless";
2
+ import * as React from "react";
3
+ export type AccordionProps = Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue"> & UseAccordionProps;
4
+ export type AccordionHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
5
+ size?: "lg" | "md";
6
+ };
7
+ export declare const AccordionHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
8
+ size?: "lg" | "md";
9
+ } & React.RefAttributes<HTMLDivElement>>;
10
+ export declare const Accordion: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange"> & UseAccordionProps & React.RefAttributes<HTMLDivElement>>;
11
+ export type AccordionItemProps = React.HTMLAttributes<HTMLDivElement> & {
12
+ value: string;
13
+ disabled?: boolean;
14
+ };
15
+ export declare const AccordionItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
16
+ value: string;
17
+ disabled?: boolean;
18
+ } & React.RefAttributes<HTMLDivElement>>;
19
+ export type AccordionTriggerProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
20
+ label?: React.ReactNode;
21
+ };
22
+ export declare const AccordionTrigger: React.ForwardRefExoticComponent<Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
23
+ label?: React.ReactNode;
24
+ } & React.RefAttributes<HTMLButtonElement>>;
25
+ export type AccordionContentProps = React.HTMLAttributes<HTMLDivElement>;
26
+ export declare const AccordionContent: React.ForwardRefExoticComponent<AccordionContentProps & React.RefAttributes<HTMLDivElement>>;
27
+ //# sourceMappingURL=Accordion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Accordion.d.ts","sourceRoot":"","sources":["../../src/accordion/Accordion.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAG/F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EACpC,UAAU,GAAG,cAAc,CAC3B,GACA,iBAAiB,CAAA;AAMlB,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG;IACzE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,eAAe;WAHpB,IAAI,GAAG,IAAI;wCAgBlB,CAAA;AA+BD,eAAO,MAAM,SAAS,oKA4CrB,CAAA;AAID,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,GAAG;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,aAAa;WAJlB,MAAM;eACF,OAAO;wCAsBlB,CAAA;AAID,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACvC,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAC7C,MAAM,CACN,GAAG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,gBAAgB;YAHpB,KAAK,CAAC,SAAS;2CAoCtB,CAAA;AAIF,MAAM,MAAM,qBAAqB,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAA;AAExE,eAAO,MAAM,gBAAgB,8FAmB3B,CAAA"}
@@ -0,0 +1,66 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAccordion } from "@gbgr/react-headless";
3
+ import { MinusIcon, PlusIcon } from "@gbgr/icons";
4
+ import clsx from "clsx";
5
+ import * as React from "react";
6
+ const AccordionContext = React.createContext(null);
7
+ export const AccordionHeader = React.forwardRef(({ className, size = "lg", children, ...props }, ref) => {
8
+ return (_jsx("div", { ...props, ref: ref, className: clsx("gbgr-accordion__header", className), "data-size": size, children: _jsx("h2", { className: "gbgr-accordion__header-title", children: children }) }));
9
+ });
10
+ AccordionHeader.displayName = "AccordionHeader";
11
+ function useAccordionContext() {
12
+ const ctx = React.useContext(AccordionContext);
13
+ if (!ctx) {
14
+ throw new Error("Accordion components must be used within <Accordion />");
15
+ }
16
+ return ctx;
17
+ }
18
+ const AccordionItemContext = React.createContext(null);
19
+ function useAccordionItemContext() {
20
+ const ctx = React.useContext(AccordionItemContext);
21
+ if (!ctx) {
22
+ throw new Error("AccordionTrigger/AccordionContent must be used within <AccordionItem />");
23
+ }
24
+ return ctx;
25
+ }
26
+ export const Accordion = React.forwardRef((props, ref) => {
27
+ const { type, value, defaultValue, onValueChange, collapsible, disabled, className, children, ...rest } = props;
28
+ const accordion = useAccordion({
29
+ type: (type ?? "single"),
30
+ value,
31
+ defaultValue,
32
+ onValueChange,
33
+ collapsible,
34
+ disabled,
35
+ });
36
+ const allChildren = React.Children.toArray(children);
37
+ const headerChild = allChildren.find((child) => {
38
+ return React.isValidElement(child) && child.type === AccordionHeader;
39
+ });
40
+ const contentChildren = allChildren.filter((child) => child !== headerChild);
41
+ return (_jsx(AccordionContext.Provider, { value: accordion, children: _jsxs("div", { ...rest, ref: ref, className: clsx("gbgr-accordion", className), "data-type": accordion.type, "data-disabled": disabled ? "" : undefined, children: [headerChild, _jsx("div", { className: "gbgr-accordion__set", children: contentChildren })] }) }));
42
+ });
43
+ Accordion.displayName = "Accordion";
44
+ export const AccordionItem = React.forwardRef((props, ref) => {
45
+ const { value, disabled, className, children, ...rest } = props;
46
+ const accordion = useAccordionContext();
47
+ const itemProps = accordion.getItemProps({ value, disabled }, rest);
48
+ return (_jsx(AccordionItemContext.Provider, { value: { value, disabled }, children: _jsx("div", { ...itemProps, ref: ref, className: clsx("gbgr-accordion__item", className), children: children }) }));
49
+ });
50
+ AccordionItem.displayName = "AccordionItem";
51
+ export const AccordionTrigger = React.forwardRef((props, ref) => {
52
+ const { className, children, label = "Q", ...rest } = props;
53
+ const accordion = useAccordionContext();
54
+ const item = useAccordionItemContext();
55
+ const triggerProps = accordion.getTriggerProps({ value: item.value, disabled: item.disabled }, rest);
56
+ return (_jsxs("button", { ...triggerProps, ref: ref, className: clsx("gbgr-accordion__trigger", className), children: [_jsxs("span", { className: "gbgr-accordion__left", children: [_jsx("span", { className: "gbgr-accordion__label", children: label }), _jsx("span", { className: "gbgr-accordion__question", children: children })] }), _jsxs("span", { className: "gbgr-accordion__icons", "aria-hidden": "true", children: [_jsx("span", { className: "gbgr-accordion__icon gbgr-accordion__icon--open", children: _jsx(MinusIcon, {}) }), _jsx("span", { className: "gbgr-accordion__icon gbgr-accordion__icon--closed", children: _jsx(PlusIcon, {}) })] })] }));
57
+ });
58
+ AccordionTrigger.displayName = "AccordionTrigger";
59
+ export const AccordionContent = React.forwardRef((props, ref) => {
60
+ const { className, children, ...rest } = props;
61
+ const accordion = useAccordionContext();
62
+ const item = useAccordionItemContext();
63
+ const contentProps = accordion.getContentProps({ value: item.value }, rest);
64
+ return (_jsx("div", { ...contentProps, ref: ref, className: clsx("gbgr-accordion__content", className), children: _jsx("div", { className: "gbgr-accordion__content-inner", children: children }) }));
65
+ });
66
+ AccordionContent.displayName = "AccordionContent";
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ export type ButtonTone = "primary" | "sub" | "grey";
3
+ export type ButtonSize = "xs" | "sm" | "md" | "lg" | "xl";
4
+ export type ButtonPressEvent = React.MouseEvent<HTMLButtonElement>;
5
+ export type ButtonProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
6
+ tone?: ButtonTone;
7
+ size?: ButtonSize;
8
+ type?: "button" | "submit" | "reset";
9
+ onPress?: (event: ButtonPressEvent) => void;
10
+ startIcon?: React.ReactNode;
11
+ endIcon?: React.ReactNode;
12
+ };
13
+ export declare const Button: React.ForwardRefExoticComponent<Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
14
+ tone?: ButtonTone;
15
+ size?: ButtonSize;
16
+ type?: "button" | "submit" | "reset";
17
+ onPress?: (event: ButtonPressEvent) => void;
18
+ startIcon?: React.ReactNode;
19
+ endIcon?: React.ReactNode;
20
+ } & React.RefAttributes<HTMLButtonElement>>;
21
+ //# sourceMappingURL=Button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/button/Button.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAA;AACnD,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAEzD,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAA;AAElE,MAAM,MAAM,WAAW,GAAG,IAAI,CAC7B,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAC7C,MAAM,CACN,GAAG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAA;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC3C,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,MAAM;WARX,UAAU;WACV,UAAU;WACV,QAAQ,GAAG,QAAQ,GAAG,OAAO;cAC1B,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI;gBAC/B,KAAK,CAAC,SAAS;cACjB,KAAK,CAAC,SAAS;2CA6DzB,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import clsx from "clsx";
3
+ import * as React from "react";
4
+ export const Button = React.forwardRef((props, ref) => {
5
+ const { tone = "primary", size = "md", className, type = "button", onClick, onPress, startIcon, endIcon, children, ...rest } = props;
6
+ const handleClick = React.useCallback((event) => {
7
+ onClick?.(event);
8
+ if (!event.defaultPrevented) {
9
+ onPress?.(event);
10
+ }
11
+ }, [onClick, onPress]);
12
+ return (_jsxs("button", { ...rest, ref: ref, type: type, onClick: handleClick, className: clsx("gbgr-button", size === "xs"
13
+ ? "gbgr-button--size-xs"
14
+ : size === "sm"
15
+ ? "gbgr-button--size-sm"
16
+ : size === "md"
17
+ ? "gbgr-button--size-md"
18
+ : size === "lg"
19
+ ? "gbgr-button--size-lg"
20
+ : "gbgr-button--size-xl", tone === "primary"
21
+ ? "gbgr-button--tone-primary"
22
+ : tone === "sub"
23
+ ? "gbgr-button--tone-sub"
24
+ : "gbgr-button--tone-grey", className), children: [startIcon ? (_jsx("span", { className: "gbgr-button__icon", children: startIcon })) : null, children, endIcon ? _jsx("span", { className: "gbgr-button__icon", children: endIcon }) : null] }));
25
+ });
26
+ Button.displayName = "Button";
@@ -0,0 +1,10 @@
1
+ export type { ButtonPressEvent, ButtonProps, ButtonSize, ButtonTone, } from "./button/Button";
2
+ export { Button } from "./button/Button";
3
+ export type { AccordionContentProps, AccordionItemProps, AccordionProps, AccordionTriggerProps, } from "./accordion/Accordion";
4
+ export { Accordion, AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, } from "./accordion/Accordion";
5
+ export type { AccordionHeaderProps } from "./accordion/Accordion";
6
+ export type { ModeToggleProps, ModeToggleValue } from "./mode-toggle/ModeToggle";
7
+ export { ModeToggle } from "./mode-toggle/ModeToggle";
8
+ export type { TextFieldProps, TextFieldState } from "./text-field/TextField";
9
+ export { TextField } from "./text-field/TextField";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACX,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,GACV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,YAAY,EACX,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACrB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,GAChB,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AACjE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { Button } from "./button/Button";
2
+ export { Accordion, AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, } from "./accordion/Accordion";
3
+ export { ModeToggle } from "./mode-toggle/ModeToggle";
4
+ export { TextField } from "./text-field/TextField";
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+ export type ModeToggleValue = "light" | "dark";
3
+ export type ModeToggleProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
4
+ value?: ModeToggleValue;
5
+ defaultValue?: ModeToggleValue;
6
+ onValueChange?: (value: ModeToggleValue) => void;
7
+ };
8
+ export declare const ModeToggle: React.ForwardRefExoticComponent<Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "type"> & {
9
+ value?: ModeToggleValue;
10
+ defaultValue?: ModeToggleValue;
11
+ onValueChange?: (value: ModeToggleValue) => void;
12
+ } & React.RefAttributes<HTMLButtonElement>>;
13
+ //# sourceMappingURL=ModeToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModeToggle.d.ts","sourceRoot":"","sources":["../../src/mode-toggle/ModeToggle.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAA;AAE9C,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAC7C,MAAM,CACN,GAAG;IACH,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,YAAY,CAAC,EAAE,eAAe,CAAA;IAC9B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CAChD,CAAA;AAED,eAAO,MAAM,UAAU;YALd,eAAe;mBACR,eAAe;oBACd,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI;2CAmChD,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { MoonIcon, SunIcon } from "@gbgr/icons";
3
+ import { useModeToggle } from "@gbgr/react-headless";
4
+ import clsx from "clsx";
5
+ import * as React from "react";
6
+ export const ModeToggle = React.forwardRef((props, ref) => {
7
+ const { className, ...rest } = props;
8
+ const { value: currentValue, buttonProps } = useModeToggle(rest);
9
+ return (_jsxs("button", { ...buttonProps, ref: ref, className: clsx("gbgr-mode-toggle", className), children: [_jsx("span", { className: "gbgr-mode-toggle__thumb", "aria-hidden": "true" }), _jsx("span", { className: clsx("gbgr-mode-toggle__icon", "gbgr-mode-toggle__icon--light"), children: _jsx(SunIcon, {}) }), _jsx("span", { className: clsx("gbgr-mode-toggle__icon", "gbgr-mode-toggle__icon--dark"), children: _jsx(MoonIcon, {}) })] }));
10
+ });
11
+ ModeToggle.displayName = "ModeToggle";
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ export type TextFieldState = "default" | "success" | "error";
3
+ export type TextFieldProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
4
+ state?: TextFieldState;
5
+ subText?: string;
6
+ subIcon?: React.ReactNode;
7
+ endAdornment?: React.ReactNode;
8
+ passwordVisible?: boolean;
9
+ defaultPasswordVisible?: boolean;
10
+ onPasswordVisibleChange?: (visible: boolean) => void;
11
+ };
12
+ export declare const TextField: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
13
+ state?: TextFieldState;
14
+ subText?: string;
15
+ subIcon?: React.ReactNode;
16
+ endAdornment?: React.ReactNode;
17
+ passwordVisible?: boolean;
18
+ defaultPasswordVisible?: boolean;
19
+ onPasswordVisibleChange?: (visible: boolean) => void;
20
+ } & React.RefAttributes<HTMLInputElement>>;
21
+ //# sourceMappingURL=TextField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../src/text-field/TextField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AAE5D,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAC3C,MAAM,CACN,GAAG;IACH,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,uBAAuB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;CACpD,CAAA;AAiBD,eAAO,MAAM,SAAS;YAxBb,cAAc;cACZ,MAAM;cACN,KAAK,CAAC,SAAS;mBACV,KAAK,CAAC,SAAS;sBACZ,OAAO;6BACA,OAAO;8BACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI;0CAqGpD,CAAA"}
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { HideIcon, InfoCircleIcon, ShowIcon } from "@gbgr/icons";
3
+ import { useTextField } from "@gbgr/react-headless";
4
+ import clsx from "clsx";
5
+ import * as React from "react";
6
+ function SuccessIcon(props) {
7
+ return (_jsxs("svg", { viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", ...props, children: [_jsx("circle", { cx: "12", cy: "12", r: "9", stroke: "currentColor", strokeWidth: "1.8" }), _jsx("path", { d: "M8.5 12.3 11 14.7 15.7 9.8", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round" })] }));
8
+ }
9
+ export const TextField = React.forwardRef((props, ref) => {
10
+ const { state = "default", subText, subIcon, endAdornment, passwordVisible, defaultPasswordVisible, onPasswordVisibleChange, className, type = "text", disabled, ...rest } = props;
11
+ const { isPassword, isPasswordVisible, inputType, togglePasswordVisible } = useTextField({
12
+ type,
13
+ disabled,
14
+ passwordVisible,
15
+ defaultPasswordVisible,
16
+ onPasswordVisibleChange,
17
+ });
18
+ const resolvedEndAdornment = React.useMemo(() => {
19
+ if (endAdornment)
20
+ return endAdornment;
21
+ if (!isPassword)
22
+ return null;
23
+ return (_jsx("button", { type: "button", className: "gbgr-text-field__button", onClick: togglePasswordVisible, "aria-label": isPasswordVisible ? "Hide password" : "Show password", disabled: disabled, children: isPasswordVisible ? _jsx(HideIcon, {}) : _jsx(ShowIcon, {}) }));
24
+ }, [
25
+ endAdornment,
26
+ isPassword,
27
+ isPasswordVisible,
28
+ togglePasswordVisible,
29
+ disabled,
30
+ ]);
31
+ const resolvedSubIcon = subIcon ??
32
+ (state === "success" ? (_jsx(SuccessIcon, {})) : state === "error" ? (_jsx(InfoCircleIcon, {})) : null);
33
+ return (_jsxs("div", { className: clsx("gbgr-text-field", className), "data-state": state, children: [_jsxs("div", { className: "gbgr-text-field__control", children: [_jsx("input", { ...rest, ref: ref, type: inputType, disabled: disabled, className: "gbgr-text-field__input" }), resolvedEndAdornment ? (_jsx("span", { className: "gbgr-text-field__end", children: resolvedEndAdornment })) : null] }), subText ? (_jsxs("div", { className: "gbgr-text-field__sub", children: [resolvedSubIcon ? (_jsx("span", { className: "gbgr-text-field__sub-icon", "aria-hidden": "true", children: resolvedSubIcon })) : null, _jsx("span", { children: subText })] })) : null] }));
34
+ });
35
+ TextField.displayName = "TextField";
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@gbgr/react",
3
+ "version": "0.1.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist",
8
+ "src"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "types": "./dist/index.d.ts"
17
+ },
18
+ "./accordion.css": "./src/accordion/accordion.css",
19
+ "./button.css": "./src/button/button.css",
20
+ "./mode-toggle.css": "./src/mode-toggle/mode-toggle.css",
21
+ "./text-field.css": "./src/text-field/text-field.css",
22
+ "./styles.css": "./src/styles.css"
23
+ },
24
+ "dependencies": {
25
+ "clsx": "^2.1.1",
26
+ "@gbgr/icons": "0.1.0",
27
+ "@gbgr/react-headless": "0.1.0"
28
+ },
29
+ "peerDependencies": {
30
+ "react": ">=18",
31
+ "react-dom": ">=18"
32
+ },
33
+ "devDependencies": {
34
+ "@types/react": "latest",
35
+ "@types/react-dom": "latest",
36
+ "react": "latest",
37
+ "react-dom": "latest",
38
+ "typescript": "latest"
39
+ },
40
+ "scripts": {
41
+ "build": "pnpm --filter @gbgr/react-headless build && tsc -p tsconfig.json",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit",
43
+ "clean": "rm -rf dist"
44
+ }
45
+ }
@@ -0,0 +1,207 @@
1
+ import { useAccordion, type AccordionType, type UseAccordionProps } from "@gbgr/react-headless"
2
+ import { MinusIcon, PlusIcon } from "@gbgr/icons"
3
+ import clsx from "clsx"
4
+ import * as React from "react"
5
+
6
+ export type AccordionProps = Omit<
7
+ React.HTMLAttributes<HTMLDivElement>,
8
+ "onChange" | "defaultValue"
9
+ > &
10
+ UseAccordionProps
11
+
12
+ type AccordionContextValue = ReturnType<typeof useAccordion>
13
+
14
+ const AccordionContext = React.createContext<AccordionContextValue | null>(null)
15
+
16
+ export type AccordionHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
17
+ size?: "lg" | "md"
18
+ }
19
+
20
+ export const AccordionHeader = React.forwardRef<HTMLDivElement, AccordionHeaderProps>(
21
+ ({ className, size = "lg", children, ...props }, ref) => {
22
+ return (
23
+ <div
24
+ {...props}
25
+ ref={ref}
26
+ className={clsx("gbgr-accordion__header", className)}
27
+ data-size={size}
28
+ >
29
+ <h2 className="gbgr-accordion__header-title">{children}</h2>
30
+ </div>
31
+ )
32
+ },
33
+ )
34
+
35
+ AccordionHeader.displayName = "AccordionHeader"
36
+
37
+ function useAccordionContext() {
38
+ const ctx = React.useContext(AccordionContext)
39
+ if (!ctx) {
40
+ throw new Error("Accordion components must be used within <Accordion />")
41
+ }
42
+ return ctx
43
+ }
44
+
45
+ type AccordionItemContextValue = {
46
+ value: string
47
+ disabled?: boolean
48
+ }
49
+
50
+ const AccordionItemContext = React.createContext<AccordionItemContextValue | null>(
51
+ null,
52
+ )
53
+
54
+ function useAccordionItemContext() {
55
+ const ctx = React.useContext(AccordionItemContext)
56
+ if (!ctx) {
57
+ throw new Error(
58
+ "AccordionTrigger/AccordionContent must be used within <AccordionItem />",
59
+ )
60
+ }
61
+ return ctx
62
+ }
63
+
64
+ export const Accordion = React.forwardRef<HTMLDivElement, AccordionProps>(
65
+ (props, ref) => {
66
+ const {
67
+ type,
68
+ value,
69
+ defaultValue,
70
+ onValueChange,
71
+ collapsible,
72
+ disabled,
73
+ className,
74
+ children,
75
+ ...rest
76
+ } = props
77
+
78
+ const accordion = useAccordion({
79
+ type: (type ?? "single") as AccordionType,
80
+ value,
81
+ defaultValue,
82
+ onValueChange,
83
+ collapsible,
84
+ disabled,
85
+ })
86
+
87
+ const allChildren = React.Children.toArray(children)
88
+ const headerChild = allChildren.find((child) => {
89
+ return React.isValidElement(child) && child.type === AccordionHeader
90
+ })
91
+ const contentChildren = allChildren.filter((child) => child !== headerChild)
92
+
93
+ return (
94
+ <AccordionContext.Provider value={accordion}>
95
+ <div
96
+ {...rest}
97
+ ref={ref}
98
+ className={clsx("gbgr-accordion", className)}
99
+ data-type={accordion.type}
100
+ data-disabled={disabled ? "" : undefined}
101
+ >
102
+ {headerChild}
103
+ <div className="gbgr-accordion__set">{contentChildren}</div>
104
+ </div>
105
+ </AccordionContext.Provider>
106
+ )
107
+ },
108
+ )
109
+
110
+ Accordion.displayName = "Accordion"
111
+
112
+ export type AccordionItemProps = React.HTMLAttributes<HTMLDivElement> & {
113
+ value: string
114
+ disabled?: boolean
115
+ }
116
+
117
+ export const AccordionItem = React.forwardRef<HTMLDivElement, AccordionItemProps>(
118
+ (props, ref) => {
119
+ const { value, disabled, className, children, ...rest } = props
120
+ const accordion = useAccordionContext()
121
+
122
+ const itemProps = accordion.getItemProps({ value, disabled }, rest)
123
+
124
+ return (
125
+ <AccordionItemContext.Provider value={{ value, disabled }}>
126
+ <div
127
+ {...itemProps}
128
+ ref={ref}
129
+ className={clsx("gbgr-accordion__item", className)}
130
+ >
131
+ {children}
132
+ </div>
133
+ </AccordionItemContext.Provider>
134
+ )
135
+ },
136
+ )
137
+
138
+ AccordionItem.displayName = "AccordionItem"
139
+
140
+ export type AccordionTriggerProps = Omit<
141
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
142
+ "type"
143
+ > & {
144
+ label?: React.ReactNode
145
+ }
146
+
147
+ export const AccordionTrigger = React.forwardRef<
148
+ HTMLButtonElement,
149
+ AccordionTriggerProps
150
+ >((props, ref) => {
151
+ const { className, children, label = "Q", ...rest } = props
152
+ const accordion = useAccordionContext()
153
+ const item = useAccordionItemContext()
154
+
155
+ const triggerProps = accordion.getTriggerProps(
156
+ { value: item.value, disabled: item.disabled },
157
+ rest,
158
+ )
159
+
160
+ return (
161
+ <button
162
+ {...triggerProps}
163
+ ref={ref}
164
+ className={clsx("gbgr-accordion__trigger", className)}
165
+ >
166
+ <span className="gbgr-accordion__left">
167
+ <span className="gbgr-accordion__label">{label}</span>
168
+ <span className="gbgr-accordion__question">{children}</span>
169
+ </span>
170
+ <span className="gbgr-accordion__icons" aria-hidden="true">
171
+ <span className="gbgr-accordion__icon gbgr-accordion__icon--open">
172
+ <MinusIcon />
173
+ </span>
174
+ <span className="gbgr-accordion__icon gbgr-accordion__icon--closed">
175
+ <PlusIcon />
176
+ </span>
177
+ </span>
178
+ </button>
179
+ )
180
+ })
181
+
182
+ AccordionTrigger.displayName = "AccordionTrigger"
183
+
184
+ export type AccordionContentProps = React.HTMLAttributes<HTMLDivElement>
185
+
186
+ export const AccordionContent = React.forwardRef<
187
+ HTMLDivElement,
188
+ AccordionContentProps
189
+ >((props, ref) => {
190
+ const { className, children, ...rest } = props
191
+ const accordion = useAccordionContext()
192
+ const item = useAccordionItemContext()
193
+
194
+ const contentProps = accordion.getContentProps({ value: item.value }, rest)
195
+
196
+ return (
197
+ <div
198
+ {...contentProps}
199
+ ref={ref}
200
+ className={clsx("gbgr-accordion__content", className)}
201
+ >
202
+ <div className="gbgr-accordion__content-inner">{children}</div>
203
+ </div>
204
+ )
205
+ })
206
+
207
+ AccordionContent.displayName = "AccordionContent"