pentatrion-design 0.0.13 → 0.0.15
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/README.md +1 -1
- package/components/autocomplete/Autocomplete.d.ts +3 -3
- package/components/autocomplete/Autocomplete.js +7 -7
- package/components/autocomplete/AutocompleteOption.d.ts +1 -3
- package/components/autocomplete/AutocompleteOption.js +3 -4
- package/components/autocomplete/LazyAutocomplete.d.ts +2 -2
- package/components/autocomplete/LazyAutocomplete.js +1 -2
- package/components/autocomplete/SimpleAutocomplete.d.ts +2 -2
- package/components/autocomplete/SimpleAutocomplete.js +1 -1
- package/components/autocomplete/_fixtures.d.ts +1 -0
- package/components/autocomplete/_fixtures.js +21 -0
- package/components/autocomplete/index.d.ts +2 -2
- package/components/autocomplete/index.js +2 -2
- package/components/badge/Badge.d.ts +1 -1
- package/components/badge/Badge.js +4 -2
- package/components/button/Button.d.ts +1 -1
- package/components/button/Button.js +1 -1
- package/components/button/Button.test.js +1 -1
- package/components/button/LinkButton.d.ts +1 -1
- package/components/button/LinkButton.js +2 -2
- package/components/context-menu/ContextMenu.js +1 -1
- package/components/dialog/Dialog.d.ts +1 -1
- package/components/dialog/Dialog.js +1 -1
- package/components/dropdown-menu/DropdownMenu.js +2 -1
- package/components/dropdown-menu/DropdownMenuContent.js +1 -1
- package/components/dropdown-menu/DropdownMenuItem.js +1 -1
- package/components/dropdown-menu/DropdownMenuTrigger.js +1 -1
- package/components/dropdown-menu/interface.d.ts +10 -0
- package/components/dropdown-menu/interface.js +1 -0
- package/components/dropdown-menu/useDropdownMenu.d.ts +1 -1
- package/components/dropdown-menu/useDropdownMenuContext.d.ts +2 -2
- package/components/dropdown-menu-nested/DropdownMenuNested.d.ts +1 -1
- package/components/dropdown-menu-nested/DropdownMenuNested.js +1 -1
- package/components/dropdown-menu-nested/MenuItemWithChildren.d.ts +1 -1
- package/components/dropdown-menu-nested/MenuItemWithChildren.js +2 -2
- package/components/flash/Flash.d.ts +1 -1
- package/components/href/Href.d.ts +1 -2
- package/components/input/Checkbox.d.ts +1 -1
- package/components/input/Color.d.ts +1 -1
- package/components/input/Color.js +1 -1
- package/components/input/Input.d.ts +1 -1
- package/components/input/Input.js +5 -5
- package/components/input/Input.test.js +1 -1
- package/components/input/RadioGroup.d.ts +1 -1
- package/components/input/RadioGroup.js +1 -1
- package/components/input/Range.d.ts +1 -1
- package/components/input/Toggle.d.ts +1 -1
- package/components/input-field/InputField.d.ts +1 -1
- package/components/input-field/InputField.js +1 -1
- package/components/loader/Loader.d.ts +1 -1
- package/components/loader/Loader.js +1 -1
- package/components/modal/Components.js +3 -3
- package/components/modal/ModalContent.js +2 -2
- package/components/modal/ModalTrigger.js +2 -2
- package/components/modal/interface.d.ts +7 -0
- package/components/modal/interface.js +1 -0
- package/components/modal/useModal.d.ts +1 -1
- package/components/modal/useModalContext.d.ts +1 -1
- package/components/notification/NotificationsContext.d.ts +1 -1
- package/components/notification/NotificationsProvider.js +1 -1
- package/components/notification/useFetch.js +1 -1
- package/components/popover/interface.d.ts +10 -0
- package/components/popover/interface.js +1 -0
- package/components/popover/usePopover.d.ts +1 -1
- package/components/popover/usePopoverContext.d.ts +1 -1
- package/components/select/Select.d.ts +1 -1
- package/components/select/Select.js +15 -11
- package/components/select/interface.d.ts +30 -0
- package/components/select/interface.js +1 -0
- package/components/snack/Snack.d.ts +1 -1
- package/components/sortable/index.d.ts +1 -1
- package/components/sortable/interface.d.ts +11 -0
- package/components/sortable/interface.js +1 -0
- package/components/textarea/Textarea.d.ts +1 -1
- package/components/tooltip/SimpleTooltip.js +3 -1
- package/components/tooltip/Tooltip.js +2 -1
- package/components/tooltip/Tooltip.test.js +1 -1
- package/components/tooltip/TooltipContent.js +2 -2
- package/components/tooltip/TooltipTrigger.js +1 -1
- package/components/tooltip/interface.d.ts +12 -0
- package/components/tooltip/interface.js +1 -0
- package/components/tooltip/useTooltip.d.ts +1 -1
- package/components/tooltip/useTooltipContext.d.ts +2 -2
- package/hooks/useRipple.js +1 -1
- package/index.d.ts +1 -1
- package/lib/error.d.ts +1 -1
- package/lib/tailwindVariants.d.ts +1 -1
- package/package.json +1 -1
- package/redux/notification/notificationSlice.d.ts +3 -3
- package/redux/notification/useReduxNotifications.d.ts +1 -1
- package/tailwind/base.js +42 -0
- package/tailwind/components.js +11 -32
- package/tailwind/utilities.js +5 -14
- package/types.d.ts +10 -0
- package/types.js +1 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# [Pentatrion Design System](https://
|
|
1
|
+
# [Pentatrion Design System](https://design.pentatrion.com)
|
|
2
2
|
|
|
3
3
|
<a href="https://design.pentatrion.com">
|
|
4
4
|
<img src="https://raw.githubusercontent.com/lhapaipai/pentatrion-design/main/screenshot.png" alt="Pentatrion design system" />
|
|
@@ -2,7 +2,7 @@ import { ReactNode } from "react";
|
|
|
2
2
|
import type { OptionLike, Option } from "../select";
|
|
3
3
|
import { AutocompleteOptionProps } from "./AutocompleteOption";
|
|
4
4
|
import { Placement } from "@floating-ui/react";
|
|
5
|
-
import { ThemeColor } from "../../types
|
|
5
|
+
import { ThemeColor } from "../../types";
|
|
6
6
|
export interface AutocompleteProps<O extends OptionLike = Option> {
|
|
7
7
|
className?: string;
|
|
8
8
|
icon?: boolean | ReactNode;
|
|
@@ -39,6 +39,6 @@ export interface AutocompleteProps<O extends OptionLike = Option> {
|
|
|
39
39
|
loading?: boolean;
|
|
40
40
|
clearSearchButton?: boolean;
|
|
41
41
|
selectOnFocus?: boolean;
|
|
42
|
+
readOnly?: boolean;
|
|
42
43
|
}
|
|
43
|
-
declare const
|
|
44
|
-
export default _default;
|
|
44
|
+
export declare const Autocomplete: <O extends OptionLike = Option>(props: AutocompleteProps<O> & import("react").RefAttributes<HTMLInputElement>) => React.ReactElement | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useCallback, useMemo, useRef, useState, forwardRef, } from "react";
|
|
4
|
-
import AutocompleteOption from "./AutocompleteOption";
|
|
4
|
+
import { AutocompleteOption } from "./AutocompleteOption";
|
|
5
5
|
import { FloatingFocusManager, FloatingList, FloatingPortal, autoUpdate, flip, offset, size, useDismiss, useFloating, useInteractions, useListNavigation, useRole, } from "@floating-ui/react";
|
|
6
6
|
import { AutocompleteContext } from "./useAutocompleteContext";
|
|
7
7
|
import clsx from "clsx";
|
|
@@ -11,7 +11,7 @@ import { Button } from "../button";
|
|
|
11
11
|
import { Dialog } from "../dialog";
|
|
12
12
|
import { Loader } from "../loader";
|
|
13
13
|
import { inputConfig } from "../input/Input";
|
|
14
|
-
function Autocomplete({ className, icon = true, color = "yellow", selectionSuffix, noSearchSuffix, placement = "bottom", placeholder = "Search...", selection = null, onChangeSelection, autocompleteOptionComponent, loading = false, clearSearchButton = false, searchValue, onChangeSearchValue, options, selectOnFocus = true, }, inputRef) {
|
|
14
|
+
export const Autocomplete = forwardRef(function Autocomplete({ className, icon = true, color = "yellow", selectionSuffix, noSearchSuffix, placement = "bottom", placeholder = "Search...", selection = null, onChangeSelection, autocompleteOptionComponent, loading = false, clearSearchButton = false, searchValue, onChangeSearchValue, options, selectOnFocus = true, readOnly = false, }, inputRef) {
|
|
15
15
|
const [isOpen, setIsOpen] = useState(false);
|
|
16
16
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
17
17
|
const onChangeSearchValueStable = useEventCallback(onChangeSearchValue);
|
|
@@ -94,9 +94,10 @@ function Autocomplete({ className, icon = true, color = "yellow", selectionSuffi
|
|
|
94
94
|
getItemProps,
|
|
95
95
|
handleSelect,
|
|
96
96
|
}), [activeIndex, selection, getItemProps, handleSelect]);
|
|
97
|
-
|
|
97
|
+
const showClearSearchButton = !readOnly && clearSearchButton && (searchValue.trim() !== "" || selection !== null);
|
|
98
|
+
return (_jsxs("div", { className: className, children: [_jsxs("div", { className: clsx(inputConfig.container, readOnly && "readonly"), ref: refs.setReference, "data-color": color, children: [icon !== false && (_jsxs("div", { className: "relative flex-center", children: [loading && _jsx(Loader, { size: "medium", color: "gray", className: "absolute left-0 top-0" }), icon === true ? (_jsx("span", { className: "h-8 w-8 flex-center", children: _jsx("i", { className: "fe-search" }) })) : (icon)] })), _jsx("input", { spellCheck: "false", className: clsx(inputConfig.input, icon === false && "pl-4"), ref: inputRef, type: "search", readOnly: readOnly, value: searchValue, placeholder: placeholder, "aria-autocomplete": "list", ...getReferenceProps({
|
|
98
99
|
onFocus() {
|
|
99
|
-
if (selectOnFocus) {
|
|
100
|
+
if (selectOnFocus && !readOnly) {
|
|
100
101
|
document.activeElement?.select();
|
|
101
102
|
}
|
|
102
103
|
},
|
|
@@ -120,7 +121,7 @@ function Autocomplete({ className, icon = true, color = "yellow", selectionSuffi
|
|
|
120
121
|
handleSelect(activeIndex);
|
|
121
122
|
}
|
|
122
123
|
},
|
|
123
|
-
}) }), _jsxs("div", { className: "relative flex-center", children: [selection && selectionSuffix,
|
|
124
|
+
}) }), _jsxs("div", { className: "relative flex-center", children: [selection && selectionSuffix, showClearSearchButton && (_jsx(Button, { withRipple: false, icon: true, color: "gray", variant: "text", onClick: () => {
|
|
124
125
|
setIsOpen(false);
|
|
125
126
|
onChangeSelectionStable(null);
|
|
126
127
|
setActiveIndex(null);
|
|
@@ -128,5 +129,4 @@ function Autocomplete({ className, icon = true, color = "yellow", selectionSuffi
|
|
|
128
129
|
}, children: _jsx("i", { className: "fe-cancel" }) })), icon === false && loading && _jsx(Loader, { size: "medium", color: "gray" }), !selection && searchValue === "" && noSearchSuffix] })] }), _jsx(FloatingPortal, { children: _jsx(AutocompleteContext.Provider, { value: autocompleteContext, children: isOpen && (_jsx(FloatingFocusManager, { disabled: selectOnFocus, context: context, initialFocus: -1, visuallyHiddenDismiss: true, children: _jsx("div", { className: "z-dialog outline-none", ref: refs.setFloating, style: floatingStyles, ...getFloatingProps(), children: _jsx(Dialog, { placement: context.placement, className: "overflow-auto motion-safe:animate-fade-in-list", children: _jsx(FloatingList, { elementsRef: listRef, children: options.map((option) => {
|
|
129
130
|
return _createElement(OptionComponent, { ...option, key: getOptionValue(option) });
|
|
130
131
|
}) }) }) }) })) }) })] }));
|
|
131
|
-
}
|
|
132
|
-
export default forwardRef(Autocomplete);
|
|
132
|
+
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import { OptionLike } from "../select";
|
|
2
2
|
export type AutocompleteOptionProps<O extends OptionLike> = O;
|
|
3
|
-
declare
|
|
4
|
-
declare const _default: import("react").MemoExoticComponent<typeof AutocompleteOption>;
|
|
5
|
-
export default _default;
|
|
3
|
+
export declare const AutocompleteOption: import("react").MemoExoticComponent<(<O extends OptionLike>(props: AutocompleteOptionProps<O>) => import("react/jsx-runtime").JSX.Element)>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { memo, useId } from "react";
|
|
3
3
|
import { useListItem } from "@floating-ui/react";
|
|
4
|
-
import { useAutocomplete } from "
|
|
4
|
+
import { useAutocomplete } from "./useAutocompleteContext";
|
|
5
5
|
import clsx from "clsx";
|
|
6
6
|
import { getOptionLabel, getOptionValue } from "./util";
|
|
7
|
-
function AutocompleteOption(props) {
|
|
7
|
+
export const AutocompleteOption = memo(function AutocompleteOption(props) {
|
|
8
8
|
const label = getOptionLabel(props);
|
|
9
9
|
const id = useId();
|
|
10
10
|
const { activeIndex, selection, getItemProps, handleSelect } = useAutocomplete();
|
|
@@ -14,5 +14,4 @@ function AutocompleteOption(props) {
|
|
|
14
14
|
return (_jsx("div", { className: clsx("option", isSelected ? "bg-gray-2" : isActive && "bg-gray-1"), ref: ref, role: "option", id: id, "aria-selected": isActive, ...getItemProps({
|
|
15
15
|
onClick: () => handleSelect(index),
|
|
16
16
|
}), children: label }));
|
|
17
|
-
}
|
|
18
|
-
export default memo(AutocompleteOption);
|
|
17
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AutocompleteProps } from "
|
|
1
|
+
import { AutocompleteProps } from "./Autocomplete";
|
|
2
2
|
import { OptionLike, Option } from "../select";
|
|
3
|
-
interface Props<O extends OptionLike = Option> extends Pick<AutocompleteProps<O>, "className" | "icon" | "color" | "selectionSuffix" | "noSearchSuffix" | "placement" | "placeholder" | "selection" | "onChangeSelection" | "autocompleteOptionComponent" | "loading" | "clearSearchButton"> {
|
|
3
|
+
interface Props<O extends OptionLike = Option> extends Pick<AutocompleteProps<O>, "className" | "icon" | "color" | "selectionSuffix" | "noSearchSuffix" | "placement" | "placeholder" | "selection" | "onChangeSelection" | "autocompleteOptionComponent" | "loading" | "clearSearchButton" | "readOnly"> {
|
|
4
4
|
onChangeSearchValueCallback: (searchValue: string) => Promise<O[]>;
|
|
5
5
|
debounce?: number;
|
|
6
6
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import { Autocomplete } from "
|
|
3
|
+
import { Autocomplete } from "./Autocomplete";
|
|
4
4
|
import { getOptionLabel } from "./util";
|
|
5
5
|
import { useStateDebounce, useEventCallback } from "../../hooks";
|
|
6
6
|
export function LazyAutocomplete({ onChangeSearchValueCallback, debounce = 5000, selection = null, onChangeSelection, ...rest }) {
|
|
7
7
|
const onChangeSelectionStable = useEventCallback(onChangeSelection);
|
|
8
8
|
const onChangeSearchValueCallbackStable = useEventCallback(onChangeSearchValueCallback);
|
|
9
9
|
const [searchValue, searchValueDebounced, setSearchValue] = useStateDebounce(selection ? getOptionLabel(selection) : "", debounce);
|
|
10
|
-
// console.log(searchValue, searchValueDebounced);
|
|
11
10
|
const searchValueRef = useRef(searchValue);
|
|
12
11
|
searchValueRef.current = searchValue;
|
|
13
12
|
const inputRef = useRef(null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AutocompleteProps } from "
|
|
1
|
+
import { AutocompleteProps } from "./Autocomplete";
|
|
2
2
|
import { Option, OptionLike } from "../select";
|
|
3
|
-
interface Props<O extends OptionLike = Option> extends Pick<AutocompleteProps<O>, "className" | "icon" | "color" | "placement" | "placeholder" | "selection" | "onChangeSelection" | "autocompleteOptionComponent" | "options" | "selection"> {
|
|
3
|
+
interface Props<O extends OptionLike = Option> extends Pick<AutocompleteProps<O>, "className" | "icon" | "color" | "placement" | "placeholder" | "selection" | "onChangeSelection" | "autocompleteOptionComponent" | "options" | "selection" | "readOnly"> {
|
|
4
4
|
}
|
|
5
5
|
export declare function SimpleAutocomplete<O extends OptionLike = Option>({ options, selection, onChangeSelection, ...rest }: Props<O>): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useLayoutEffect, useRef, useState } from "react";
|
|
3
|
-
import { Autocomplete } from "
|
|
3
|
+
import { Autocomplete } from "./Autocomplete";
|
|
4
4
|
import { useEventCallback } from "../../hooks";
|
|
5
5
|
import { getOptionLabel } from "./util";
|
|
6
6
|
export function SimpleAutocomplete({ options, selection = null, onChangeSelection, ...rest }) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Fuse from "fuse.js";
|
|
1
2
|
export const options = [
|
|
2
3
|
{ value: "abbeville", label: "Abbeville" },
|
|
3
4
|
{ value: "agde", label: "Agde" },
|
|
@@ -23,3 +24,23 @@ export const options = [
|
|
|
23
24
|
{ value: "avoriaz", label: "Avoriaz" },
|
|
24
25
|
{ value: "avray", label: "Avray" },
|
|
25
26
|
];
|
|
27
|
+
async function mockServerRequest(searchValue) {
|
|
28
|
+
await new Promise((resolve) => {
|
|
29
|
+
setTimeout(resolve, Math.random() * 1000);
|
|
30
|
+
});
|
|
31
|
+
const res = await fetch(`/town-74.json`);
|
|
32
|
+
const towns = (await res.json());
|
|
33
|
+
const fuse = new Fuse(towns, {
|
|
34
|
+
minMatchCharLength: 2,
|
|
35
|
+
keys: ["nom_commune"],
|
|
36
|
+
});
|
|
37
|
+
const results = fuse.search(searchValue);
|
|
38
|
+
return results.map(({ item }) => ({
|
|
39
|
+
label: item.context,
|
|
40
|
+
value: item.insee,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
export const handleChangeSearchValue = async (searchValue) => {
|
|
44
|
+
const results = await mockServerRequest(searchValue);
|
|
45
|
+
return results;
|
|
46
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Autocomplete, type AutocompleteProps } from "./Autocomplete";
|
|
2
2
|
export { SimpleAutocomplete } from "./SimpleAutocomplete";
|
|
3
|
-
export {
|
|
3
|
+
export { AutocompleteOption } from "./AutocompleteOption";
|
|
4
4
|
export { LazyAutocomplete } from "./LazyAutocomplete";
|
|
5
5
|
export { useAutocomplete } from "./useAutocompleteContext";
|
|
6
6
|
export { getOptionValue, getOptionLabel } from "./util";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Autocomplete } from "./Autocomplete";
|
|
2
2
|
export { SimpleAutocomplete } from "./SimpleAutocomplete";
|
|
3
|
-
export {
|
|
3
|
+
export { AutocompleteOption } from "./AutocompleteOption";
|
|
4
4
|
export { LazyAutocomplete } from "./LazyAutocomplete";
|
|
5
5
|
export { useAutocomplete } from "./useAutocompleteContext";
|
|
6
6
|
export { getOptionValue, getOptionLabel } from "./util";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import clsx from "clsx";
|
|
3
|
-
import { buttonVariants } from "../button";
|
|
3
|
+
import { buttonVariants } from "../button/Button";
|
|
4
4
|
import { Href } from "../href";
|
|
5
|
-
import { Tooltip
|
|
5
|
+
import { Tooltip } from "../tooltip/Tooltip";
|
|
6
|
+
import { TooltipContent } from "../tooltip/TooltipContent";
|
|
7
|
+
import { TooltipTrigger } from "../tooltip/TooltipTrigger";
|
|
6
8
|
export function Badge({ children, className, onRemove, onClick, tooltip, url, color = "yellow", }) {
|
|
7
9
|
const badge = (_jsxs("span", { className: clsx("ll-badge", "inline-flex w-fit items-stretch overflow-hidden rounded-full text-xs shadow", buttonVariants.variant.contained(color),
|
|
8
10
|
// badgeVariants.color[color],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithRef } from "react";
|
|
2
|
-
import { ThemeColor } from "../../types
|
|
2
|
+
import { ThemeColor } from "../../types";
|
|
3
3
|
export interface ButtonProps extends ComponentPropsWithRef<"button"> {
|
|
4
4
|
withRipple?: boolean;
|
|
5
5
|
variant?: "contained" | "light" | "outlined" | "text" | "ghost";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useRef
|
|
2
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
import { Loader } from "../loader";
|
|
5
5
|
import { useRipple } from "../../hooks";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cleanup, fireEvent, render } from "@testing-library/react";
|
|
3
3
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
4
|
-
import { Button } from "
|
|
4
|
+
import { Button } from "./Button";
|
|
5
5
|
afterEach(cleanup);
|
|
6
6
|
describe("<Button />", () => {
|
|
7
7
|
it("forwards className", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useRef
|
|
2
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { useRipple } from "../../hooks";
|
|
4
|
+
import { useRipple } from "../../hooks/useRipple";
|
|
5
5
|
import { buttonVariants } from "./Button";
|
|
6
6
|
export const LinkButton = forwardRef(function LinkButton({ withRipple = true, variant = "contained", color = "yellow", size = "medium", focusable = true, fullWidth, className, children, selected = false, icon = false, href, ...props }, ref) {
|
|
7
7
|
const anchorRef = useRef(null);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Children, cloneElement, isValidElement, useEffect, useRef, useState, } from "react";
|
|
3
3
|
import { FloatingFocusManager, FloatingPortal, autoUpdate, flip, offset, shift, size, useDismiss, useFloating, useInteractions, useListNavigation, useRole, useTypeahead, } from "@floating-ui/react";
|
|
4
|
-
import { Dialog } from "../dialog";
|
|
4
|
+
import { Dialog } from "../dialog/Dialog";
|
|
5
5
|
import { useEventCallback, useRefDebounce } from "../../hooks";
|
|
6
6
|
export function ContextMenu({ targetRef, children, style, eventName = "contextmenu" }) {
|
|
7
7
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Placement } from "@floating-ui/react";
|
|
2
2
|
import { ComponentProps, ReactNode } from "react";
|
|
3
|
-
import type { ThemeColor } from "../../types
|
|
3
|
+
import type { ThemeColor } from "../../types";
|
|
4
4
|
interface Props extends ComponentProps<"div"> {
|
|
5
5
|
color?: ThemeColor;
|
|
6
6
|
placement?: Placement;
|
|
@@ -16,5 +16,5 @@ export const dialogVariants = {
|
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
18
|
export function Dialog({ placement, color, children, className, ...rest }) {
|
|
19
|
-
return (_jsx("div", { className: clsx("rounded-2xl
|
|
19
|
+
return (_jsx("div", { className: clsx("relative rounded-2xl shadow dark:shadow-dark", dialogVariants.color(color), className), "data-placement": placement, "data-color": color, ...rest, children: children }));
|
|
20
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { DropdownMenuContext
|
|
2
|
+
import { DropdownMenuContext } from "./useDropdownMenuContext";
|
|
3
|
+
import { useDropdownMenu } from "./useDropdownMenu";
|
|
3
4
|
export function DropdownMenu({ children, ...options }) {
|
|
4
5
|
const popover = useDropdownMenu(options);
|
|
5
6
|
return _jsx(DropdownMenuContext.Provider, { value: popover, children: children });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import { useDropdownMenuContext } from "
|
|
3
|
+
import { useDropdownMenuContext } from "./useDropdownMenuContext";
|
|
4
4
|
import { FloatingFocusManager, FloatingList, FloatingPortal, useMergeRefs, } from "@floating-ui/react";
|
|
5
5
|
import clsx from "clsx";
|
|
6
6
|
import { Dialog } from "../dialog";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useListItem } from "@floating-ui/react";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { useDropdownMenuContext } from "
|
|
4
|
+
import { useDropdownMenuContext } from "./useDropdownMenuContext";
|
|
5
5
|
export function DropdownMenuItem({ children, onClick, ...rest }) {
|
|
6
6
|
const { activeIndex, getItemProps, handleSelect } = useDropdownMenuContext();
|
|
7
7
|
const { ref, index } = useListItem({ label: children?.toString() });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { cloneElement, forwardRef, isValidElement } from "react";
|
|
3
|
-
import { useDropdownMenuContext } from "
|
|
3
|
+
import { useDropdownMenuContext } from "./useDropdownMenuContext";
|
|
4
4
|
import { useMergeRefs } from "@floating-ui/react";
|
|
5
5
|
import { Button } from "../button";
|
|
6
6
|
export const DropdownMenuTrigger = forwardRef(({ children, asChild = false, ...props }, propRef) => {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Placement } from "@floating-ui/react";
|
|
2
|
+
import { ThemeColor } from "../../types";
|
|
3
|
+
export interface DropdownMenuOptions {
|
|
4
|
+
initialOpen?: boolean;
|
|
5
|
+
placement?: Placement;
|
|
6
|
+
open?: boolean;
|
|
7
|
+
onOpen?: (open: boolean) => void;
|
|
8
|
+
color?: ThemeColor | "default";
|
|
9
|
+
modal?: boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import type { DropdownMenuOptions } from "./interface";
|
|
|
2
2
|
export declare function useDropdownMenu({ initialOpen, placement, open: controlledOpen, onOpen: setControlledOpen, color, modal, }: DropdownMenuOptions): {
|
|
3
3
|
elementsRef: import("react").MutableRefObject<(HTMLElement | null)[]>;
|
|
4
4
|
labelsRef: import("react").MutableRefObject<(string | null)[]>;
|
|
5
|
-
color: import("
|
|
5
|
+
color: import("../..").ThemeColor | "default";
|
|
6
6
|
modal: boolean;
|
|
7
7
|
activeIndex: number | null;
|
|
8
8
|
handleSelect: () => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { useDropdownMenu } from "
|
|
1
|
+
import { useDropdownMenu } from "./useDropdownMenu";
|
|
2
2
|
type ContextType = ReturnType<typeof useDropdownMenu> | null;
|
|
3
3
|
export declare const DropdownMenuContext: import("react").Context<ContextType>;
|
|
4
4
|
export declare function useDropdownMenuContext(): {
|
|
5
5
|
elementsRef: import("react").MutableRefObject<(HTMLElement | null)[]>;
|
|
6
6
|
labelsRef: import("react").MutableRefObject<(string | null)[]>;
|
|
7
|
-
color: import("
|
|
7
|
+
color: import("../..").ThemeColor | "default";
|
|
8
8
|
modal: boolean;
|
|
9
9
|
activeIndex: number | null;
|
|
10
10
|
handleSelect: () => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
|
-
import { MenuItemWithChildren } from "
|
|
3
|
+
import { MenuItemWithChildren } from "./MenuItemWithChildren";
|
|
4
4
|
import { FloatingTree } from "@floating-ui/react";
|
|
5
5
|
export const DropdownMenuNested = forwardRef((props, ref) => {
|
|
6
6
|
return (_jsx(FloatingTree, { children: _jsx(MenuItemWithChildren, { ...props, ref: ref }) }));
|
|
@@ -3,8 +3,8 @@ import { FloatingFocusManager, FloatingList, FloatingNode, FloatingPortal, autoU
|
|
|
3
3
|
import { forwardRef, useContext, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { MenuContext } from "./MenuContext";
|
|
5
5
|
import clsx from "clsx";
|
|
6
|
-
import { Button } from "../button";
|
|
7
|
-
import { Dialog } from "../dialog";
|
|
6
|
+
import { Button } from "../button/Button";
|
|
7
|
+
import { Dialog } from "../dialog/Dialog";
|
|
8
8
|
export const MenuItemWithChildren = forwardRef(({ children, label, triggerComponent: TriggerComponent = Button, ...props }, forwardedRef) => {
|
|
9
9
|
const [isOpen, setIsOpen] = useState(false);
|
|
10
10
|
const [hasFocusInside, setHasFocusInside] = useState(false);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
-
interface Props extends ComponentPropsWithRef<"a"> {
|
|
2
|
+
export interface Props extends ComponentPropsWithRef<"a"> {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
ghost?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare const Href: (props: Props & import("react").RefAttributes<HTMLAnchorElement>) => React.ReactElement | null;
|
|
7
|
-
export {};
|
|
@@ -7,5 +7,5 @@ export const Color = forwardRef(({ value, withRipple = true, color = "yellow", l
|
|
|
7
7
|
const buttonRef = useRef(null);
|
|
8
8
|
useImperativeHandle(ref, () => buttonRef.current);
|
|
9
9
|
const ripples = useRipple(buttonRef);
|
|
10
|
-
return (_jsxs("button", { ref: buttonRef, "data-color": color, className: "p8n-input-text relative flex h-8 overflow-clip rounded-2xl p-1 outline-offset-[-1px]", ...rest, children: [withRipple && ripples, _jsx("span", { className: clsx("flex items-center justify-center rounded-2xl px-2", valueToShow === null && "min-w-12", className), style: { backgroundColor: value }, children: valueToShow })] }));
|
|
10
|
+
return (_jsxs("button", { ref: buttonRef, "data-color": color, className: "p8n-input-text relative flex h-8 overflow-clip rounded-2xl p-1 outline-offset-[-1px]", ...rest, children: [withRipple && ripples, _jsx("span", { className: clsx("flex h-full items-center justify-center rounded-2xl px-2", valueToShow === null && "min-w-12", className), style: { backgroundColor: value }, children: valueToShow })] }));
|
|
11
11
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithRef, ReactNode } from "react";
|
|
2
|
-
import type { ThemeColor } from "../../types
|
|
2
|
+
import type { ThemeColor } from "../../types";
|
|
3
3
|
export interface InputProps extends Omit<ComponentPropsWithRef<"input">, "prefix"> {
|
|
4
4
|
variant?: "normal" | "ghost";
|
|
5
5
|
disabled?: boolean;
|
|
@@ -5,12 +5,12 @@ export const inputConfig = {
|
|
|
5
5
|
container: "p8n-input-text rounded-2xl outline-offset-[-1px] flex ",
|
|
6
6
|
input: "h-8 flex-1 appearance-none outline-none filter-none min-w-0 bg-transparent",
|
|
7
7
|
};
|
|
8
|
-
export const Input = forwardRef(({ variant = "normal", color = "yellow", disabled = false, prefix, suffix, className, ...rest }, ref) => {
|
|
9
|
-
return (_jsxs("div", { "data-color": color, "data-variant": variant, className: clsx(inputConfig.container, disabled && "disabled", className), children: [prefix && (_jsx("div", { className: clsx([
|
|
10
|
-
"flex-center
|
|
8
|
+
export const Input = forwardRef(({ variant = "normal", color = "yellow", disabled = false, prefix, suffix, className, readOnly, ...rest }, ref) => {
|
|
9
|
+
return (_jsxs("div", { "data-color": color, "data-variant": variant, className: clsx(inputConfig.container, disabled && "disabled", readOnly && "readonly", className), children: [prefix && (_jsx("div", { className: clsx([
|
|
10
|
+
"relative flex-center",
|
|
11
11
|
typeof prefix === "string" && "mx-2 select-none text-gray-6",
|
|
12
|
-
]), children: prefix })), _jsx("input", { ref: ref, className: clsx(inputConfig.input, !prefix && "pl-4", !suffix && "pr-4"),
|
|
13
|
-
"flex-center
|
|
12
|
+
]), children: prefix })), _jsx("input", { ref: ref, className: clsx(inputConfig.input, !prefix && "pl-4", !suffix && "pr-4"), disabled: disabled, readOnly: readOnly, ...rest }), suffix && (_jsx("div", { className: clsx([
|
|
13
|
+
"relative flex-center",
|
|
14
14
|
typeof suffix === "string" && "mx-2 select-none text-gray-6",
|
|
15
15
|
]), children: suffix }))] }));
|
|
16
16
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { describe, it, expect } from "vitest";
|
|
3
3
|
import { render } from "@testing-library/react";
|
|
4
|
-
import { Input } from "
|
|
4
|
+
import { Input } from "./Input";
|
|
5
5
|
describe("Input component", () => {
|
|
6
6
|
it("forward className to <input> element", () => {
|
|
7
7
|
const { container } = render(_jsx(Input, { className: "custom" }));
|
|
@@ -5,7 +5,7 @@ import clsx from "clsx";
|
|
|
5
5
|
export const Radio = forwardRef(({ disabled = false, color = "yellow", checked, children, name, className, ...rest }, ref) => {
|
|
6
6
|
const inputRef = useRef(null);
|
|
7
7
|
const combinedRef = useCombinedRefs(inputRef, ref);
|
|
8
|
-
return (_jsxs("label", { className: clsx("flex items-center
|
|
8
|
+
return (_jsxs("label", { className: clsx("flex cursor-pointer items-center", disabled && "disabled"), children: [_jsx("input", { "data-color": color, ref: combinedRef, disabled: disabled, type: "radio", className: clsx("p8n-input-radio", "my-0 mr-1 inline-block h-5 w-5 shrink-0 cursor-pointer select-none appearance-none rounded-full bg-gray-0 bg-origin-border p-0", className), checked: checked, name: name, ...rest }), children] }));
|
|
9
9
|
});
|
|
10
10
|
const placementVariants = {
|
|
11
11
|
inline: "flex gap-2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentPropsWithRef } from "react";
|
|
2
|
-
import { ThemeColor } from "../../types
|
|
2
|
+
import { ThemeColor } from "../../types";
|
|
3
3
|
export interface RangeProps extends Omit<ComponentPropsWithRef<"input">, "value" | "min" | "max" | "step"> {
|
|
4
4
|
value: number;
|
|
5
5
|
min?: number;
|
|
@@ -8,6 +8,6 @@ interface InputFieldOwnProps {
|
|
|
8
8
|
warning?: ReactNode | boolean;
|
|
9
9
|
}
|
|
10
10
|
declare const defaultElement: (props: import("../input/Input").InputProps & import("react").RefAttributes<HTMLInputElement>) => React.ReactElement | null;
|
|
11
|
-
type Props<E extends ElementType> = PolymorphicPropsWithRef<InputFieldOwnProps, E>;
|
|
11
|
+
export type Props<E extends ElementType> = PolymorphicPropsWithRef<InputFieldOwnProps, E>;
|
|
12
12
|
export declare const InputField: <E extends ElementType = typeof defaultElement>(props: Props<E>) => ReactNode;
|
|
13
13
|
export {};
|
|
@@ -6,7 +6,7 @@ const InputFieldBase = ({ label, hint, help, error, warning, as, ...rest }, ref)
|
|
|
6
6
|
const id = useId();
|
|
7
7
|
const Element = as || defaultElement;
|
|
8
8
|
const labelElement = label && _jsx("span", { className: "font-bold", children: label });
|
|
9
|
-
const hintElement = hint &&
|
|
9
|
+
const hintElement = hint && _jsx("span", { className: "ml-auto text-sm text-gray-6", children: hint });
|
|
10
10
|
const errorElement = error && typeof error !== "boolean" && (_jsxs("span", { className: "font-medium text-red-4 dark:text-red-2", children: [_jsx("i", { className: "fe-circle-exclamation" }), _jsx("span", { children: error })] }));
|
|
11
11
|
const warningElement = warning && typeof warning !== "boolean" && (_jsxs("span", { className: "font-medium text-orange-4 dark:text-orange-2", children: [_jsx("i", { className: "fe-circle-exclamation" }), _jsx("span", { children: warning })] }));
|
|
12
12
|
const color = error ? "red" : warning ? "orange" : "yellow";
|
|
@@ -24,5 +24,5 @@ const circleStyle = {
|
|
|
24
24
|
};
|
|
25
25
|
export function Loader({ size = "medium", color = "blue", className, ...rest }) {
|
|
26
26
|
const id = useId();
|
|
27
|
-
return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: clsx("inline-block", sizeConfig[size], colorVariants[color].text, className), viewBox: "0 0 16 16", ...rest, children: [_jsx("defs", { children: _jsx("circle", { id: id, cx: "8", cy: "8", r: "7" }) }), _jsx("use", { href: `#${id}`, className: "
|
|
27
|
+
return (_jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", className: clsx("inline-block", sizeConfig[size], colorVariants[color].text, className), viewBox: "0 0 16 16", ...rest, children: [_jsx("defs", { children: _jsx("circle", { id: id, cx: "8", cy: "8", r: "7" }) }), _jsx("use", { href: `#${id}`, className: "fill-none stroke-current opacity-25", style: trackStyle }), _jsx("use", { href: `#${id}`, className: "animate-loader-stroke fill-none stroke-current", style: circleStyle })] }));
|
|
28
28
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useModalContext } from "
|
|
2
|
+
import { useModalContext } from "./useModalContext";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { Button } from "../button";
|
|
5
|
-
import { Scroll } from "../scroll";
|
|
4
|
+
import { Button } from "../button/Button";
|
|
5
|
+
import { Scroll } from "../scroll/Scroll";
|
|
6
6
|
export function ModalHeader({ children, className, closeButton = true, ...props }) {
|
|
7
7
|
const { setOpen } = useModalContext();
|
|
8
8
|
return (_jsxs(_Fragment, { children: [closeButton && (_jsx("div", { className: "float-right p-1", children: _jsx(Button, { icon: true, variant: "text", color: "gray", onClick: () => setOpen(false), children: _jsx("i", { className: "fe-cancel" }) }) })), _jsx("header", { className: clsx("flex items-center px-2 pt-2", className), ...props, children: _jsx("h4", { className: "font-semibold leading-6", children: children }) })] }));
|