@uxf/ui 1.0.0-beta.18 → 1.0.0-beta.23

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.
@@ -0,0 +1,10 @@
1
+ import { UseAnchorProps } from "@uxf/core/hooks/useAnchorProps";
2
+ import { AnchorHTMLAttributes, HTMLAttributes } from "react";
3
+ interface ItemProps extends AnchorHTMLAttributes<HTMLAnchorElement>, UseAnchorProps {
4
+ }
5
+ declare type ItemsProps = HTMLAttributes<HTMLDivElement>;
6
+ export declare const Dropdown: {
7
+ Item: import("react").ForwardRefExoticComponent<ItemProps & import("react").RefAttributes<HTMLAnchorElement>>;
8
+ Items: import("react").ForwardRefExoticComponent<ItemsProps & import("react").RefAttributes<HTMLDivElement>>;
9
+ };
10
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Dropdown = void 0;
4
+ const useAnchorProps_1 = require("@uxf/core/hooks/useAnchorProps");
5
+ const forwardRef_1 = require("@uxf/ui/utils/forwardRef");
6
+ function Item(props, ref) {
7
+ const { children, className, ...restProps } = props;
8
+ const anchorProps = (0, useAnchorProps_1.useAnchorProps)({
9
+ className: `uxf-dropdown-item ${className || ""}`,
10
+ role: "menuitem",
11
+ ...restProps,
12
+ });
13
+ return (<a ref={ref} {...anchorProps}>
14
+ {children}
15
+ </a>);
16
+ }
17
+ function Items(props, ref) {
18
+ const { children, className, role = "menu", ...restProps } = props;
19
+ return (<div className={`uxf-dropdown-items`} ref={ref} role={role} {...restProps}>
20
+ {children}
21
+ </div>);
22
+ }
23
+ exports.Dropdown = {
24
+ Item: (0, forwardRef_1.forwardRef)("Item.", Item),
25
+ Items: (0, forwardRef_1.forwardRef)("Items", Items),
26
+ };
@@ -0,0 +1 @@
1
+ export { Dropdown } from "./dropdown";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Dropdown = void 0;
4
+ var dropdown_1 = require("./dropdown");
5
+ Object.defineProperty(exports, "Dropdown", { enumerable: true, get: function () { return dropdown_1.Dropdown; } });
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from "react";
2
+ interface Props {
3
+ id?: string | undefined;
4
+ children?: ReactNode;
5
+ }
6
+ declare function ErrorMessage(props: Props): JSX.Element;
7
+ export default ErrorMessage;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function ErrorMessage(props) {
4
+ return (<p id={props.id} className="uxf-error-message">
5
+ {props.children}
6
+ </p>);
7
+ }
8
+ exports.default = ErrorMessage;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { Avatar } from "./avatar";
2
+ import { ErrorMessage } from "./index";
3
3
  declare const _default: {
4
4
  title: string;
5
- component: typeof Avatar;
5
+ component: typeof ErrorMessage;
6
6
  };
7
7
  export default _default;
8
8
  export declare function Default(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Default = void 0;
4
+ const index_1 = require("./index");
5
+ exports.default = {
6
+ title: "UI/ErrorMessage",
7
+ component: index_1.ErrorMessage,
8
+ };
9
+ function Default() {
10
+ return (<div className="space-y-2">
11
+ <index_1.ErrorMessage>This field is required.</index_1.ErrorMessage>
12
+ </div>);
13
+ }
14
+ exports.Default = Default;
@@ -0,0 +1 @@
1
+ export { default as ErrorMessage } from "./error-message";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ErrorMessage = void 0;
7
+ var error_message_1 = require("./error-message");
8
+ Object.defineProperty(exports, "ErrorMessage", { enumerable: true, get: function () { return __importDefault(error_message_1).default; } });
@@ -0,0 +1,7 @@
1
+ import { Placement } from "@floating-ui/react-dom";
2
+ import { CSSProperties } from "react";
3
+ export declare function useDropdown(placement: Placement, matchWidth?: boolean): {
4
+ floating: (node: HTMLElement | null) => void;
5
+ reference: (node: (Element | import("@floating-ui/core").VirtualElement) | null) => void;
6
+ style: Partial<CSSProperties>;
7
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDropdown = void 0;
4
+ const react_dom_1 = require("@floating-ui/react-dom");
5
+ const react_1 = require("react");
6
+ function useDropdown(placement, matchWidth = false) {
7
+ var _a, _b;
8
+ const [sizeData, setSizeData] = (0, react_1.useState)(null);
9
+ const { floating, reference, refs, strategy, update, x, y } = (0, react_dom_1.useFloating)({
10
+ placement,
11
+ middleware: [
12
+ (0, react_dom_1.flip)(),
13
+ (0, react_dom_1.shift)(),
14
+ (0, react_dom_1.size)({
15
+ apply: setSizeData,
16
+ }),
17
+ ],
18
+ });
19
+ (0, react_1.useEffect)(() => {
20
+ if (!refs.reference.current || !refs.floating.current) {
21
+ return;
22
+ }
23
+ return (0, react_dom_1.autoUpdate)(refs.reference.current, refs.floating.current, update);
24
+ }, [refs.reference, refs.floating, update]);
25
+ return {
26
+ floating,
27
+ reference,
28
+ style: {
29
+ left: x !== null && x !== void 0 ? x : undefined,
30
+ maxHeight: (_a = sizeData === null || sizeData === void 0 ? void 0 : sizeData.height) !== null && _a !== void 0 ? _a : undefined,
31
+ maxWidth: matchWidth ? (_b = sizeData === null || sizeData === void 0 ? void 0 : sizeData.reference.width) !== null && _b !== void 0 ? _b : undefined : undefined,
32
+ position: strategy,
33
+ top: y !== null && y !== void 0 ? y : undefined,
34
+ },
35
+ };
36
+ }
37
+ exports.useDropdown = useDropdown;
@@ -0,0 +1 @@
1
+ export { default as Label } from "./label";
package/label/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Label = void 0;
7
+ var label_1 = require("./label");
8
+ Object.defineProperty(exports, "Label", { enumerable: true, get: function () { return __importDefault(label_1).default; } });
@@ -0,0 +1,9 @@
1
+ import { MouseEventHandler, ReactNode } from "react";
2
+ export interface LabelProps {
3
+ children?: ReactNode;
4
+ htmlFor?: string;
5
+ form?: string;
6
+ onClick?: MouseEventHandler<HTMLLabelElement>;
7
+ }
8
+ declare const _default: import("react").ForwardRefExoticComponent<LabelProps & import("react").RefAttributes<HTMLLabelElement>>;
9
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const forwardRef_1 = require("@uxf/ui/utils/forwardRef");
4
+ function Label(props, ref) {
5
+ return (<label className="uxf-label" ref={ref} htmlFor={props.htmlFor} form={props.form} onClick={props.onClick}>
6
+ {props.children}
7
+ </label>);
8
+ }
9
+ exports.default = (0, forwardRef_1.forwardRef)("Label", Label);
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ declare const _default: {
3
+ title: string;
4
+ component: import("react").ForwardRefExoticComponent<import("./label").LabelProps & import("react").RefAttributes<HTMLLabelElement>>;
5
+ };
6
+ export default _default;
7
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Default = void 0;
4
+ const index_1 = require("./index");
5
+ exports.default = {
6
+ title: "UI/Label",
7
+ component: index_1.Label,
8
+ };
9
+ function Default() {
10
+ return (<div className="space-y-2">
11
+ <index_1.Label>Label</index_1.Label>
12
+ </div>);
13
+ }
14
+ exports.Default = Default;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "1.0.0-beta.18",
3
+ "version": "1.0.0-beta.23",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
8
  "scripts": {
9
- "build": "yarn compile",
9
+ "build": "npm run compile",
10
10
  "compile": "tsc -P tsconfig.json",
11
- "typecheck": "tsc --noEmit --skipLibCheck",
12
- "prepublish": "yarn build"
11
+ "typecheck": "tsc --noEmit --skipLibCheck"
13
12
  },
14
13
  "author": "",
15
14
  "license": "MIT",
16
15
  "dependencies": {
16
+ "@floating-ui/react-dom": "^0.6.0",
17
+ "@headlessui/react": "^1.6.6",
17
18
  "@uxf/core": "latest"
18
- },
19
- "stableVersion": "1.0.0-beta.15"
20
- }
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ export { default as Select } from "./select";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Select = void 0;
7
+ var select_1 = require("./select");
8
+ Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return __importDefault(select_1).default; } });
@@ -0,0 +1,27 @@
1
+ import { FocusEventHandler } from "react";
2
+ export declare type SelectValue = number | string;
3
+ export declare type SelectOption<T = SelectValue> = {
4
+ key?: number | string;
5
+ id: T;
6
+ label: string;
7
+ disabled?: boolean;
8
+ };
9
+ export interface SelectProps<V = SelectValue, O = SelectOption<V>> {
10
+ className?: string;
11
+ disabled?: boolean;
12
+ error?: string;
13
+ invalid?: boolean;
14
+ onChange: (value: O | null) => void;
15
+ onBlur?: FocusEventHandler<HTMLDivElement>;
16
+ onFocus?: FocusEventHandler<HTMLDivElement>;
17
+ name: string;
18
+ id: string;
19
+ label: string;
20
+ placeholder?: string;
21
+ options: O[];
22
+ readOnly?: boolean;
23
+ required?: boolean;
24
+ value?: V;
25
+ }
26
+ declare const _default: import("react").ForwardRefExoticComponent<SelectProps<SelectValue, SelectOption<SelectValue>> & import("react").RefAttributes<HTMLDivElement>>;
27
+ export default _default;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("@headlessui/react");
4
+ const dropdown_1 = require("../dropdown");
5
+ const use_dropdown_1 = require("../hooks/use-dropdown");
6
+ const classes_1 = require("@uxf/core/constants/classes");
7
+ const useInputFocus_1 = require("@uxf/core/hooks/useInputFocus");
8
+ const composeRefs_1 = require("@uxf/core/utils/composeRefs");
9
+ const cx_1 = require("@uxf/core/utils/cx");
10
+ const react_2 = require("react");
11
+ const error_message_1 = require("../error-message");
12
+ const label_1 = require("../label");
13
+ const forwardRef_1 = require("@uxf/ui/utils/forwardRef");
14
+ function Select(props, ref) {
15
+ const { className, disabled, error, id, invalid, label, onBlur, onChange, onFocus, options, placeholder = "Vyberte z možností...", readOnly, value, } = props;
16
+ const selectedOption = (0, react_2.useMemo)(() => options.find((option) => option.id === value), [options, value]);
17
+ const innerRef = (0, react_2.useRef)(null);
18
+ const disabledOrReadOnly = disabled || readOnly;
19
+ const errorId = invalid ? `${id}--errormessage` : undefined;
20
+ const input = (0, useInputFocus_1.useInputFocus)(innerRef, onBlur, onFocus);
21
+ const dropdown = (0, use_dropdown_1.useDropdown)("bottom", true);
22
+ const stableRef = (0, react_2.useMemo)(() => (0, composeRefs_1.composeRefs)(innerRef, ref, dropdown.reference), [ref, dropdown.reference]);
23
+ return (<react_1.Listbox as="div" className={`select-form-field ${className || ""}`} onChange={onChange} value={selectedOption}>
24
+ <react_1.Listbox.Label as={label_1.Label} onClick={!disabledOrReadOnly ? input.focus : undefined}>
25
+ {label}
26
+ </react_1.Listbox.Label>
27
+ <react_1.Listbox.Button as="div">
28
+ {(b) => (
29
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
30
+ <div aria-invalid={invalid} aria-describedby={errorId} className={(0, cx_1.cx)("select-text-input__control select-text-input__control--select", (b.open || input.focused) && classes_1.CLASSES.IS_FOCUSED, b.disabled && classes_1.CLASSES.IS_DISABLED, readOnly && classes_1.CLASSES.IS_READONLY, invalid && classes_1.CLASSES.IS_INVALID)} onBlur={input.onBlur} onFocus={input.onFocus} tabIndex={!disabledOrReadOnly ? 0 : undefined} ref={stableRef}>
31
+ <div className={`select-text-input ${!value ? "text-gray-muted" : ""}`}>
32
+ {(selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || placeholder}
33
+ </div>
34
+ {b.open ? "▲" : "▼"}
35
+ </div>)}
36
+ </react_1.Listbox.Button>
37
+ {invalid && error && <error_message_1.ErrorMessage id={errorId}>{error}</error_message_1.ErrorMessage>}
38
+ <react_1.Listbox.Options as={dropdown_1.Dropdown.Items} className="w-full" ref={dropdown.floating} style={dropdown.style}>
39
+ {options.map((option) => (<react_1.Listbox.Option as={react_2.Fragment} key={option.key || option.id} value={option}>
40
+ {(o) => (<dropdown_1.Dropdown.Item className={(0, cx_1.cx)(o.active && classes_1.CLASSES.IS_ACTIVE, o.disabled && classes_1.CLASSES.IS_DISABLED, o.selected && classes_1.CLASSES.IS_SELECTED)}>
41
+ {option.label}
42
+ </dropdown_1.Dropdown.Item>)}
43
+ </react_1.Listbox.Option>))}
44
+ </react_1.Listbox.Options>
45
+ </react_1.Listbox>);
46
+ }
47
+ exports.default = (0, forwardRef_1.forwardRef)("Select", Select);
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { SelectOption, SelectValue } from "./select";
3
+ declare const _default: {
4
+ title: string;
5
+ component: import("react").ForwardRefExoticComponent<import("./select").SelectProps<SelectValue, SelectOption<SelectValue>> & import("react").RefAttributes<HTMLDivElement>>;
6
+ };
7
+ export default _default;
8
+ export declare function Default(): JSX.Element;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Default = void 0;
4
+ const index_1 = require("./index");
5
+ exports.default = {
6
+ title: "UI/Select",
7
+ component: index_1.Select,
8
+ };
9
+ const options = [
10
+ { id: "one", label: "Option one" },
11
+ { id: "two", label: "Option two" },
12
+ { id: "three", label: "Option three" },
13
+ ];
14
+ function Default() {
15
+ const handleChange = (value) => {
16
+ console.log("Select value: ", value);
17
+ };
18
+ return (<div className="space-y-2">
19
+ <index_1.Select id={"select-1"} name="select" label="Choose option..." options={options} onChange={handleChange}/>
20
+ </div>);
21
+ }
22
+ exports.Default = Default;
@@ -8,6 +8,7 @@ export interface StorybookConfig {
8
8
  colors: Array<keyof ButtonColors>;
9
9
  };
10
10
  Input: {};
11
+ Select: {};
11
12
  }
12
13
  export declare function useStorybookConfig<T extends keyof StorybookConfig>(key: T): StorybookConfig[T];
13
14
  interface StorybookContextProviderProps {
@@ -32,6 +32,7 @@ exports.defaultConfig = {
32
32
  variants: ["outlined", "default"],
33
33
  },
34
34
  Input: {},
35
+ Select: {},
35
36
  };
36
37
  // Context
37
38
  const Context = react_1.default.createContext(exports.defaultConfig);
@@ -1,14 +0,0 @@
1
- /// <reference types="react" />
2
- import { AvatarSizes } from "./theme";
3
- interface FileResponse {
4
- uuid: string;
5
- namespace?: string;
6
- extension: string;
7
- }
8
- export interface AvatarProps {
9
- src: FileResponse | string | null | undefined;
10
- size?: keyof AvatarSizes;
11
- rounded?: boolean;
12
- }
13
- export declare function Avatar(props: AvatarProps): JSX.Element;
14
- export {};
package/avatar/avatar.jsx DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Avatar = void 0;
4
- const cx_1 = require("@uxf/core/utils/cx");
5
- function Avatar(props) {
6
- var _a;
7
- const className = (0, cx_1.cx)("avatar", `avatar--size-${props.size}`, `avatar--variant-${(_a = props.circular) !== null && _a !== void 0 ? _a : "default"}`);
8
- return <img src={props.src} className={className}/>;
9
- }
10
- exports.Avatar = Avatar;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Default = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const storybook_config_1 = require("@uxf/ui/utils/storybook-config");
9
- const avatar_1 = require("./avatar");
10
- exports.default = {
11
- title: "UI/Avatar",
12
- component: avatar_1.Avatar,
13
- };
14
- function Default() {
15
- const config = (0, storybook_config_1.useStorybookConfig)("Button");
16
- return (<div className="space-y-4">
17
- <div className="flex flex-row items-center space-x-4">
18
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="8"/>
19
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="10"/>
20
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="12"/>
21
- </div>
22
- <div className="flex flex-row items-center space-x-4">
23
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="8" variant="circular"/>
24
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="10" variant="circular"/>
25
- <avatar_1.Avatar src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80" size="12" variant="circular"/>
26
- </div>
27
- </div>);
28
- }
29
- exports.Default = Default;
package/avatar/theme.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export interface AvatarSizes {
2
- "8": true;
3
- "10": true;
4
- "12": true;
5
- }
package/avatar/theme.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });