@js-empire/emperor-ui 1.2.4 → 1.2.6

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.
Files changed (70) hide show
  1. package/README.md +226 -20
  2. package/dist/emperor-ui.js +126 -115
  3. package/dist/emperor-ui.umd.cjs +28 -14
  4. package/dist/globals.css +1 -1
  5. package/dist/{index-CYORMghp.js → index-CLEmvl4g.js} +2 -2
  6. package/dist/index-DceZlwg2.js +5 -0
  7. package/dist/{index-CDB93OLO.js → index-KrC7oBFa.js} +18241 -14332
  8. package/dist/index.d.ts +162 -32
  9. package/dist/src-UW24ZMRV-DfI_MdGD.js +5 -0
  10. package/package.json +4 -2
  11. package/src/components/atoms/color-picker/color-picker.tsx +0 -1
  12. package/src/components/atoms/color-picker/free-color-picker.tsx +8 -10
  13. package/src/components/atoms/color-picker/preset-color-picker.tsx +5 -3
  14. package/src/components/atoms/color-picker/stories/color-picker.stories.tsx +25 -11
  15. package/src/components/atoms/field/field.tsx +75 -5
  16. package/src/components/atoms/field/index.ts +2 -0
  17. package/src/components/atoms/field/units/autocomplete-field.tsx +49 -0
  18. package/src/components/atoms/field/units/checkbox-field.tsx +35 -0
  19. package/src/components/atoms/field/units/index.ts +7 -0
  20. package/src/components/atoms/field/units/input-field.tsx +35 -0
  21. package/src/components/atoms/field/units/radio-field.tsx +43 -0
  22. package/src/components/atoms/field/units/select-field.tsx +50 -0
  23. package/src/components/atoms/field/units/switch-field.tsx +35 -0
  24. package/src/components/atoms/field/units/textarea-field.tsx +37 -0
  25. package/src/components/atoms/filter/filter.tsx +2 -1
  26. package/src/components/atoms/filter/stories/filter.stories.tsx +148 -7
  27. package/src/components/atoms/filter/units/autocomplete-filter.tsx +38 -11
  28. package/src/components/atoms/filter/units/checkbox-filter.tsx +16 -6
  29. package/src/components/atoms/filter/units/checkbox-group-filter.tsx +40 -9
  30. package/src/components/atoms/filter/units/date-filter.tsx +18 -22
  31. package/src/components/atoms/filter/units/numeric-filter.tsx +12 -7
  32. package/src/components/atoms/filter/units/range-filter.tsx +42 -13
  33. package/src/components/atoms/filter/units/search-filter.tsx +8 -7
  34. package/src/components/atoms/filter/units/select-filter.tsx +17 -9
  35. package/src/components/atoms/filter/units/switch-filter.tsx +6 -4
  36. package/src/components/organisms/form-builder/form-builder.stories.tsx +144 -0
  37. package/src/components/organisms/form-builder/form-builder.tsx +75 -0
  38. package/src/components/organisms/form-builder/index.ts +1 -0
  39. package/src/components/organisms/index.ts +1 -1
  40. package/src/constants/defaults.ts +40 -0
  41. package/src/context/form-builder-context.tsx +8 -0
  42. package/src/context/index.ts +1 -0
  43. package/src/hooks/index.ts +1 -0
  44. package/src/hooks/use-filters.ts +2 -2
  45. package/src/hooks/use-form-builder-context.ts +16 -0
  46. package/src/providers/config-provider.tsx +8 -0
  47. package/src/providers/form-builder-provider-context.tsx +18 -0
  48. package/src/providers/index.ts +1 -0
  49. package/src/styles/globals.css +26 -1
  50. package/src/styles/hero.ts +1 -0
  51. package/src/styles/index.css +0 -5
  52. package/src/types/components/atoms/color-picker/color-picker.ts +10 -1
  53. package/src/types/components/atoms/field/field.ts +53 -1
  54. package/src/types/components/atoms/filter/filter.ts +26 -17
  55. package/src/types/components/organisms/form-builder/context.ts +6 -0
  56. package/src/types/components/organisms/form-builder/form-builder.ts +39 -0
  57. package/src/types/components/organisms/form-builder/index.ts +2 -0
  58. package/src/types/components/organisms/index.ts +1 -0
  59. package/src/types/context/config.ts +2 -0
  60. package/src/types/context/index.ts +1 -0
  61. package/src/types/context/theme.ts +33 -0
  62. package/dist/index-BXtdEByK.js +0 -5
  63. package/dist/src-UW24ZMRV-C1Pn8-w8.js +0 -5
  64. package/src/components/atoms/color-picker/styles/color-picker.css +0 -23
  65. package/src/components/atoms/field/field.stories.tsx +0 -27
  66. package/src/components/organisms/filters/filters.stories.tsx +0 -32
  67. package/src/components/organisms/filters/filters.tsx +0 -36
  68. package/src/components/organisms/filters/index.ts +0 -1
  69. package/src/components/organisms/filters/styles/classes.ts +0 -9
  70. package/src/components/organisms/filters/styles/index.ts +0 -1
@@ -0,0 +1,18 @@
1
+ import type { FieldValues } from "react-hook-form";
2
+ import type { ReactNode } from "react";
3
+ import { FormBuilderValue } from "@/types";
4
+ import { FormBuilderContext } from "@/context";
5
+
6
+ export function FormBuilderProvider<TSchema extends FieldValues>({
7
+ children,
8
+ value,
9
+ }: {
10
+ children: ReactNode;
11
+ value: FormBuilderValue<TSchema>;
12
+ }) {
13
+ return (
14
+ <FormBuilderContext.Provider value={value as FormBuilderValue<FieldValues>}>
15
+ {children}
16
+ </FormBuilderContext.Provider>
17
+ );
18
+ }
@@ -3,3 +3,4 @@ export * from "./emperor-ui-provider";
3
3
  export * from "./navigation-provider";
4
4
  export * from "./uploader-provider";
5
5
  export * from "./theme-provider";
6
+ export * from "./form-builder-provider-context";
@@ -1,7 +1,8 @@
1
1
  @import "tailwindcss";
2
2
  @plugin './hero.ts';
3
3
  @source '../../node_modules/@heroui/theme/dist/**/*.{js,ts,jsx,tsx}';
4
- @custom-variant dark (&:is(.dark *));
4
+
5
+ /* @custom-variant dark (&:is(.dark *)); */
5
6
 
6
7
  .scrollbar-hide {
7
8
  -ms-overflow-style: none; /* IE and Edge */
@@ -11,3 +12,27 @@
11
12
  .scrollbar-hide::-webkit-scrollbar {
12
13
  display: none; /* Chrome, Safari, Opera */
13
14
  }
15
+
16
+ /* Rounded corners and compact size for native color input swatch */
17
+ .color-swatch {
18
+ width: 1.25rem;
19
+ height: 1.25rem;
20
+ min-width: 1.25rem;
21
+ min-height: 1.25rem;
22
+ cursor: pointer;
23
+ }
24
+
25
+ .color-swatch::-webkit-color-swatch-wrapper {
26
+ padding: 0;
27
+ border-radius: 0.375rem;
28
+ }
29
+
30
+ .color-swatch::-webkit-color-swatch {
31
+ border: none;
32
+ border-radius: 0.375rem;
33
+ }
34
+
35
+ .color-swatch::-moz-color-swatch {
36
+ border: none;
37
+ border-radius: 0.375rem;
38
+ }
@@ -1,2 +1,3 @@
1
1
  import { heroui } from "@heroui/theme";
2
+
2
3
  export default heroui();
@@ -1,14 +1,9 @@
1
1
  @import "tailwindcss";
2
2
 
3
3
  :root {
4
- font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
5
4
  line-height: 1.5;
6
5
  font-weight: 400;
7
-
8
6
  color-scheme: light dark;
9
- color: rgba(255, 255, 255, 0.87);
10
- background-color: #242424;
11
-
12
7
  font-synthesis: none;
13
8
  text-rendering: optimizeLegibility;
14
9
  -webkit-font-smoothing: antialiased;
@@ -5,8 +5,17 @@ export type ColorPickerInputType = "free" | "preset";
5
5
 
6
6
  export type ColorPickerProps = Omit<
7
7
  InputProps & SelectProps,
8
- "onChange" | "children"
8
+ | "onChange"
9
+ | "onValueChange"
10
+ | "onSelectionChange"
11
+ | "children"
12
+ | "selectedKeys"
13
+ | "defaultSelectedKeys"
14
+ | "value"
9
15
  > & {
10
16
  inputType: ColorPickerInputType;
11
17
  presets?: string[];
18
+ onChange?: (value: string) => void;
19
+ value?: string;
20
+ defaultValue?: string;
12
21
  };
@@ -1,9 +1,61 @@
1
1
  import type { SharedComponentProps } from "@/types";
2
+ import type {
3
+ AutocompleteItemProps,
4
+ AutocompleteProps,
5
+ } from "@heroui/autocomplete";
6
+ import type { CheckboxProps } from "@heroui/checkbox";
7
+ import type { InputProps, TextAreaProps } from "@heroui/input";
8
+ import type { RadioGroupProps } from "@heroui/radio";
9
+ import type { SelectItemProps, SelectProps } from "@heroui/select";
10
+ import type { SwitchProps } from "@heroui/switch";
11
+ import type { FieldValues, Path } from "react-hook-form";
2
12
 
3
13
  export type FieldClassnames = {
4
14
  base?: string;
15
+ field?: string;
5
16
  };
6
17
 
7
- export type FieldProps = SharedComponentProps & {
18
+ export type FieldType =
19
+ | "input"
20
+ | "textarea"
21
+ | "checkbox"
22
+ | "select"
23
+ | "autocomplete"
24
+ | "switch"
25
+ | "radio";
26
+
27
+ export type FieldOption = {
28
+ key: string;
29
+ label: string;
30
+ };
31
+
32
+ type FieldTypesProps = {
33
+ inputProps?: InputProps;
34
+ textareaProps?: TextAreaProps;
35
+ checkboxProps?: CheckboxProps;
36
+ selectProps?: Omit<
37
+ SelectProps,
38
+ "children" | "selectedKeys" | "onSelectionChange"
39
+ >;
40
+ selectItemProps?: SelectItemProps;
41
+ autocompleteProps?: Omit<
42
+ AutocompleteProps,
43
+ "children" | "selectedKey" | "onSelectionChange"
44
+ >;
45
+ autocompleteItemProps?: AutocompleteItemProps;
46
+ switchProps?: SwitchProps;
47
+ radioGroupProps?: Omit<
48
+ RadioGroupProps,
49
+ "children" | "value" | "onValueChange"
50
+ >;
51
+ };
52
+
53
+ type SharedFieldProps<TFieldValues extends FieldValues> = {
8
54
  classNames?: FieldClassnames;
55
+ type: FieldType;
56
+ name: Path<TFieldValues>;
57
+ options?: FieldOption[];
9
58
  };
59
+
60
+ export type FieldProps<TFieldValues extends FieldValues = FieldValues> =
61
+ SharedComponentProps & FieldTypesProps & SharedFieldProps<TFieldValues>;
@@ -1,11 +1,11 @@
1
1
  import type { SelectFilterProps, SharedComponentProps } from "@/types";
2
- import { AutocompleteProps } from "@heroui/autocomplete";
2
+ import { AutocompleteItemProps, AutocompleteProps } from "@heroui/autocomplete";
3
3
  import { CheckboxGroupProps } from "@heroui/checkbox";
4
4
  import { CheckboxProps } from "@heroui/checkbox";
5
5
  import { DatePickerProps } from "@heroui/date-picker";
6
6
  import { InputProps } from "@heroui/input";
7
7
  import { RadioProps } from "@heroui/radio";
8
- import { SelectProps } from "@heroui/select";
8
+ import { SelectItemProps, SelectProps } from "@heroui/select";
9
9
  import { SliderProps } from "@heroui/slider";
10
10
  import { SwitchProps } from "@heroui/switch";
11
11
 
@@ -25,19 +25,28 @@ export type FilterType =
25
25
  | "switch"
26
26
  | "range";
27
27
 
28
+ type FilterTypesProps = {
29
+ searchProps?: InputProps;
30
+ selectProps?: Omit<SelectProps, "children">;
31
+ selectItemProps?: SelectItemProps;
32
+ autocompleteProps?: Omit<AutocompleteProps, "children">;
33
+ autocompleteItemProps?: AutocompleteItemProps;
34
+ dateProps?: DatePickerProps;
35
+ numericProps?: InputProps;
36
+ checkboxProps?: CheckboxProps;
37
+ checkboxGroupProps?: Omit<CheckboxGroupProps, "children">;
38
+ radioProps?: RadioProps;
39
+ switchProps?: SwitchProps;
40
+ rangeProps?: SliderProps;
41
+ };
42
+
43
+ type SharedFilterProps = {
44
+ classNames?: FilterClassnames;
45
+ type: FilterType;
46
+ paramKey: string;
47
+ };
48
+
28
49
  export type FilterProps = SharedComponentProps &
29
- SelectFilterProps & {
30
- classNames?: FilterClassnames;
31
- type: FilterType;
32
- paramKey: string;
33
- searchProps?: InputProps;
34
- selectProps?: Omit<SelectProps, "children">;
35
- autocompleteProps?: AutocompleteProps;
36
- dateProps?: DatePickerProps;
37
- numericProps?: InputProps;
38
- checkboxProps?: CheckboxProps;
39
- checkboxGroupProps?: CheckboxGroupProps;
40
- radioProps?: RadioProps;
41
- switchProps?: SwitchProps;
42
- rangeProps?: SliderProps;
43
- };
50
+ SelectFilterProps &
51
+ FilterTypesProps &
52
+ SharedFilterProps;
@@ -0,0 +1,6 @@
1
+ import { Control, FieldValues } from "react-hook-form";
2
+
3
+ export type FormBuilderValue<TSchema extends FieldValues> = {
4
+ control: Control<TSchema, any, TSchema>;
5
+ formValues: Partial<TSchema>;
6
+ };
@@ -0,0 +1,39 @@
1
+ import type { SharedComponentProps } from "@/types";
2
+ import { ReactNode } from "react";
3
+ import type {
4
+ FieldErrors,
5
+ FieldValues,
6
+ UseFormProps,
7
+ UseFormReturn,
8
+ } from "react-hook-form";
9
+ import type { ZodType } from "zod";
10
+ import { z } from "zod";
11
+
12
+ export type FormBuilderSubmitArgs<TFieldValues extends FieldValues> = {
13
+ values: TFieldValues;
14
+ form: UseFormReturn<TFieldValues>;
15
+ };
16
+
17
+ export type FormBuilderSuccessArgs<TFieldValues extends FieldValues> = {
18
+ values: TFieldValues;
19
+ form: UseFormReturn<TFieldValues>;
20
+ };
21
+
22
+ export type FormBuilderErrorArgs<TFieldValues extends FieldValues> = {
23
+ error?: unknown;
24
+ errors?: FieldErrors<TFieldValues>;
25
+ form: UseFormReturn<TFieldValues>;
26
+ };
27
+
28
+ export type FormBuilderProps<TSchema extends ZodType<any, any, any>> = Omit<
29
+ SharedComponentProps,
30
+ "children"
31
+ > & {
32
+ children: ReactNode;
33
+ formProps?: UseFormProps<z.infer<TSchema>>;
34
+ onSubmit: (values: z.infer<TSchema>) => Promise<unknown> | unknown;
35
+ onSuccess?: (values: z.infer<TSchema>) => void;
36
+ onError?: (error: unknown) => void;
37
+ /** Called whenever form values change. Use this to read values outside FormBuilder (e.g. in parent state). */
38
+ onValuesChange?: (values: Partial<z.infer<TSchema>>) => void;
39
+ };
@@ -0,0 +1,2 @@
1
+ export type * from "./form-builder";
2
+ export type * from "./context";
@@ -1 +1,2 @@
1
1
  export * from "./filters";
2
+ export * from "./form-builder";
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { EmperorUIInterLocalization } from "@/types";
3
3
  import { ToastProps } from "@heroui/toast";
4
+ import { EmperorUITheme } from "@/types";
4
5
 
5
6
  export type ConfigContextState = {
6
7
  config: EmperorUIConfig;
@@ -19,4 +20,5 @@ export type EmperorUIConfig = {
19
20
  layout?: Partial<EmperorUILayout>;
20
21
  interLocalization?: Partial<EmperorUIInterLocalization>;
21
22
  toast?: ToastProps;
23
+ theme?: Partial<EmperorUITheme>;
22
24
  };
@@ -1,3 +1,4 @@
1
1
  export type * from "./config";
2
2
  export type * from "./navigation";
3
3
  export type * from "./localization";
4
+ export type * from "./theme";
@@ -0,0 +1,33 @@
1
+ import { InputProps, TextAreaProps } from "@heroui/input";
2
+ import { ButtonProps } from "@heroui/button";
3
+ import { CardProps } from "@heroui/card";
4
+ import { DropdownProps } from "@heroui/dropdown";
5
+ import { ModalProps } from "@heroui/modal";
6
+ import { CheckboxGroupProps, CheckboxProps } from "@heroui/checkbox";
7
+ import { AutocompleteItemProps, AutocompleteProps } from "@heroui/autocomplete";
8
+ import { SelectProps, SelectItemProps } from "@heroui/select";
9
+ import { RadioProps } from "@heroui/radio";
10
+ import { SwitchProps } from "@heroui/switch";
11
+ import { DatePickerProps } from "@heroui/date-picker";
12
+ import { SliderProps } from "@heroui/slider";
13
+
14
+ export type EmperorUITheme = {
15
+ components?: {
16
+ input?: InputProps;
17
+ textarea?: TextAreaProps;
18
+ button?: ButtonProps;
19
+ card?: CardProps;
20
+ dropdown?: DropdownProps;
21
+ modal?: ModalProps;
22
+ checkbox?: CheckboxProps;
23
+ checkboxGroup?: CheckboxGroupProps;
24
+ autocomplete?: Omit<AutocompleteProps, "children">;
25
+ autocompleteItem?: Omit<AutocompleteItemProps, "children">;
26
+ radio?: Omit<RadioProps, "children">;
27
+ select?: Omit<SelectProps, "children">;
28
+ selectItem?: Omit<SelectItemProps, "children">;
29
+ switch?: SwitchProps;
30
+ datePicker?: DatePickerProps;
31
+ slider?: SliderProps;
32
+ };
33
+ };
@@ -1,5 +0,0 @@
1
- import { d as a } from "./index-CDB93OLO.js";
2
- var o = a;
3
- export {
4
- o as default
5
- };
@@ -1,5 +0,0 @@
1
- import { d as a } from "./index-CDB93OLO.js";
2
- var r = a;
3
- export {
4
- r as default
5
- };
@@ -1,23 +0,0 @@
1
- /* Rounded corners and compact size for native color input swatch */
2
- .color-swatch {
3
- width: 1.25rem;
4
- height: 1.25rem;
5
- min-width: 1.25rem;
6
- min-height: 1.25rem;
7
- cursor: pointer;
8
- }
9
-
10
- .color-swatch::-webkit-color-swatch-wrapper {
11
- padding: 0;
12
- border-radius: 0.375rem;
13
- }
14
-
15
- .color-swatch::-webkit-color-swatch {
16
- border: none;
17
- border-radius: 0.375rem;
18
- }
19
-
20
- .color-swatch::-moz-color-swatch {
21
- border: none;
22
- border-radius: 0.375rem;
23
- }
@@ -1,27 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react-vite";
2
- import { Field } from "@/components";
3
- import { getStorybookDecorators } from "@/utils";
4
-
5
- const meta: Meta<typeof Field> = {
6
- title: "Atoms/Field",
7
- component: Field,
8
- parameters: {
9
- layout: "centered",
10
- },
11
- tags: ["autodocs"],
12
- decorators: getStorybookDecorators({
13
- config: {
14
- layout: {
15
- withScaffold: false,
16
- },
17
- },
18
- }),
19
- };
20
-
21
- export default meta;
22
-
23
- type Story = StoryObj<typeof meta>;
24
-
25
- export const Default: Story = {
26
- args: {},
27
- };
@@ -1,32 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react-vite";
2
- import { Filter, Filters } from "@/components";
3
- import { getStorybookDecorators } from "@/utils";
4
-
5
- const meta: Meta<typeof Filters> = {
6
- title: "Organisms/Filters",
7
- component: Filters,
8
- parameters: {
9
- layout: "centered",
10
- },
11
- tags: ["autodocs"],
12
- decorators: getStorybookDecorators({
13
- config: {
14
- layout: {
15
- withScaffold: false,
16
- },
17
- },
18
- }),
19
- };
20
-
21
- export default meta;
22
-
23
- type Story = StoryObj<typeof meta>;
24
-
25
- export const Default: Story = {
26
- args: {},
27
- render: () => (
28
- <Filters>
29
- <Filter type="search" paramKey="search" />
30
- </Filters>
31
- ),
32
- };
@@ -1,36 +0,0 @@
1
- import { cn } from "@/utils";
2
- import { FilterProps, FiltersProps } from "@/types";
3
- import { filtersClasses } from "./styles";
4
- import { Children, isValidElement, ReactElement } from "react";
5
- import { Filter } from "@/components";
6
-
7
- export function Filters({
8
- className,
9
- classNames,
10
- children,
11
- ...props
12
- }: FiltersProps) {
13
- const childArray = Children.toArray(children).filter(
14
- isValidElement,
15
- ) as ReactElement<FilterProps, typeof Filter>[];
16
-
17
- childArray.forEach((child) => {
18
- const type = child.type;
19
-
20
- if (type !== Filter) {
21
- throw new Error(
22
- `Allowed children for <Filters /> must be of type <Filter />. Got ${type} instead.`,
23
- );
24
- }
25
- });
26
-
27
- return (
28
- <nav
29
- data-slot="emperor-ui-filters"
30
- className={cn(filtersClasses({}), className)}
31
- {...props}
32
- >
33
- <ul className="flex items-center gap-2">{children}</ul>
34
- </nav>
35
- );
36
- }
@@ -1 +0,0 @@
1
- export * from "./filters";
@@ -1,9 +0,0 @@
1
- import { cva } from "class-variance-authority";
2
-
3
- export const filtersClasses = cva([""], {
4
- variants: {
5
- variant: {},
6
- },
7
- defaultVariants: {},
8
- compoundVariants: [],
9
- });
@@ -1 +0,0 @@
1
- export * from "./classes";