@omer-x/tailwind-ui-kit 1.0.0-alpha.13 → 1.0.0-alpha.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.
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { useRender } from '@base-ui/react/use-render';
3
3
 
4
- declare const AnimatedPopup: ({ render, ...otherProps }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
4
+ declare const AnimatedPopup: ({ render, className, ...otherProps }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
5
 
6
6
  export { AnimatedPopup as default };
@@ -1,7 +1,7 @@
1
1
  import { mergeProps } from "@base-ui/react/merge-props";
2
2
  import { useRender } from "@base-ui/react/use-render";
3
3
  import { cn } from "../../utils/cn.js";
4
- const AnimatedPopup = ({ render, ...otherProps }) => useRender({
4
+ const AnimatedPopup = ({ render, className, ...otherProps }) => useRender({
5
5
  defaultTagName: "div",
6
6
  render,
7
7
  props: mergeProps({
@@ -24,7 +24,8 @@ const AnimatedPopup = ({ render, ...otherProps }) => useRender({
24
24
  "data-[nested-dialog-open]:after:rounded-[inherit]",
25
25
  "data-[nested-dialog-open]:after:bg-black/5",
26
26
  "data-[starting-style]:scale-90",
27
- "data-[starting-style]:opacity-0"
27
+ "data-[starting-style]:opacity-0",
28
+ className
28
29
  )
29
30
  }, otherProps)
30
31
  });
@@ -5,10 +5,12 @@ import '@base-ui/react/use-render';
5
5
 
6
6
  type BaseFormProps = Omit<ComponentProps<"form">, "action"> & {
7
7
  action: (initialState: unknown, formData: FormData) => Promise<Record<string, string>>;
8
+ defaultValues?: Record<string, unknown>;
9
+ onlyDirty?: boolean;
8
10
  messages?: Partial<Record<string, string>>;
9
11
  renderMessages?: ComponentProps<typeof JustDiv>["render"];
10
- onlyDirty?: boolean;
12
+ onStateChange?: (state: Record<string, string>) => void;
11
13
  };
12
- declare const BaseForm: ({ action, messages: messageTranslations, renderMessages, onlyDirty, className, children, }: BaseFormProps) => react.JSX.Element;
14
+ declare const BaseForm: ({ action, defaultValues, onlyDirty, messages: messageTranslations, renderMessages, onStateChange, className, children, }: BaseFormProps) => react.JSX.Element;
13
15
 
14
16
  export { BaseForm as default };
@@ -1,21 +1,26 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { Form } from "@base-ui/react/form";
4
- import { useActionState, useRef } from "react";
4
+ import { useActionState, useEffect, useRef } from "react";
5
5
  import { getDirtyFormData } from "../../utils/dirty-form.js";
6
6
  import JustDiv from "../elements/JustDiv.js";
7
7
  import { FormContext } from "./FormContext.js";
8
8
  const BaseForm = ({
9
9
  action,
10
+ defaultValues = {},
11
+ onlyDirty = false,
10
12
  messages: messageTranslations = {},
11
13
  renderMessages,
12
- onlyDirty = false,
14
+ onStateChange,
13
15
  className,
14
16
  children
15
17
  }) => {
16
18
  const [state, formAction, _loading] = useActionState(action, {});
17
19
  const fieldsRef = useRef(/* @__PURE__ */ new Set());
18
20
  const formRef = useRef(null);
21
+ useEffect(() => {
22
+ onStateChange?.(state);
23
+ }, [state]);
19
24
  const getFieldMessage = (fieldName) => {
20
25
  if (fieldName in state) {
21
26
  return state[fieldName];
@@ -41,7 +46,7 @@ const BaseForm = ({
41
46
  if (!onlyDirty) return formAction(fd);
42
47
  const form = formRef.current;
43
48
  if (!form) return formAction(fd);
44
- return formAction(getDirtyFormData(form));
49
+ return formAction(getDirtyFormData(form, defaultValues));
45
50
  };
46
51
  return /* @__PURE__ */ jsxs(Form, { ref: formRef, action: alteredAction, className, errors: fieldMessages, children: [
47
52
  Object.entries(formMessages).map(([messageKey, message]) => /* @__PURE__ */ jsx(
@@ -14,7 +14,8 @@ type BaseFormFieldProps = {
14
14
  renderLabel?: ComponentProps<typeof Field.Label>["render"];
15
15
  renderErrors?: ComponentProps<typeof Field.Error>["render"];
16
16
  clientSideErrors?: Partial<Record<keyof ValidityState, string | ((payload: string | number | null) => string)>>;
17
+ className?: string;
17
18
  };
18
- declare const BaseFormField: ({ schema, name, label, messages, control, renderLabel, renderErrors, clientSideErrors, }: BaseFormFieldProps) => react.JSX.Element;
19
+ declare const BaseFormField: ({ schema, name, label, messages, control, renderLabel, renderErrors, clientSideErrors, className, }: BaseFormFieldProps) => react.JSX.Element;
19
20
 
20
21
  export { BaseFormField as default };
@@ -1,6 +1,7 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Field } from "@base-ui/react/field";
3
3
  import { getErrorMessagePayload, getFieldConstraints } from "@omer-x/zod-to-form-constraints";
4
+ import { cn } from "../../utils/cn.js";
4
5
  import JustInput from "../elements/JustInput.js";
5
6
  import FieldRoot from "./FieldRoot.js";
6
7
  import ServerSideError from "./ServerSideError.js";
@@ -12,8 +13,9 @@ const BaseFormField = ({
12
13
  control,
13
14
  renderLabel,
14
15
  renderErrors,
15
- clientSideErrors = {}
16
- }) => /* @__PURE__ */ jsxs(FieldRoot, { name, className: "flex w-full flex-col items-start gap-1", children: [
16
+ clientSideErrors = {},
17
+ className
18
+ }) => /* @__PURE__ */ jsxs(FieldRoot, { name, className: cn("flex w-full flex-col items-start gap-1", className), children: [
17
19
  typeof label !== "undefined" && /* @__PURE__ */ jsx(Field.Label, { render: renderLabel, children: label }),
18
20
  /* @__PURE__ */ jsx(JustInput, { name, render: control, ...getFieldConstraints(schema) }),
19
21
  Object.entries(clientSideErrors).map(([stateName, message]) => /* @__PURE__ */ jsx(Field.Error, { match: stateName, render: renderErrors, children: typeof message === "string" ? message : message(getErrorMessagePayload(schema, stateName)) }, stateName)),
@@ -1,8 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentProps } from 'react';
3
- import { Input } from '@base-ui/react/input';
3
+ import JustInput from '../elements/JustInput.js';
4
+ import '@base-ui/react/use-render';
4
5
 
5
- type BaseInputProps = Omit<ComponentProps<typeof Input>, "size"> & {
6
+ type BaseInputProps = Omit<ComponentProps<typeof JustInput>, "size"> & {
6
7
  size?: "lg" | "md" | "sm" | "xs";
7
8
  };
8
9
  declare const BaseInput: ({ size, className, ...otherProps }: BaseInputProps) => react.JSX.Element;
@@ -1,14 +1,15 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { Input } from "@base-ui/react/input";
3
2
  import {} from "react";
4
3
  import { cn } from "../../utils/cn.js";
4
+ import JustInput from "../elements/JustInput.js";
5
5
  const BaseInput = ({
6
6
  size = "md",
7
7
  className,
8
8
  ...otherProps
9
9
  }) => /* @__PURE__ */ jsx(
10
- Input,
10
+ JustInput,
11
11
  {
12
+ ...otherProps,
12
13
  className: cn({
13
14
  // Size
14
15
  "h-12 px-5 text-base": size === "lg",
@@ -22,8 +23,7 @@ const BaseInput = ({
22
23
  "outline-offset-2",
23
24
  "outline-transparent",
24
25
  "transition-colors"
25
- ], className),
26
- ...otherProps
26
+ ], className)
27
27
  }
28
28
  );
29
29
  var BaseInput_default = BaseInput;
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import { Switch } from '@base-ui/react/switch';
4
+
5
+ type BaseSwitchProps = ComponentProps<typeof Switch.Root> & {
6
+ label: ReactNode;
7
+ renderThumb?: ComponentProps<typeof Switch.Thumb>["render"];
8
+ };
9
+ declare const BaseSwitch: ({ label, renderThumb, value, uncheckedValue, className, ...otherProps }: BaseSwitchProps) => react.JSX.Element;
10
+
11
+ export { BaseSwitch as default };
@@ -0,0 +1,52 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Switch } from "@base-ui/react/switch";
3
+ import {} from "react";
4
+ import { cn } from "../../utils/cn.js";
5
+ const BaseSwitch = ({
6
+ label,
7
+ renderThumb,
8
+ value = "true",
9
+ uncheckedValue = "false",
10
+ className,
11
+ ...otherProps
12
+ }) => /* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 text-sm font-normal", children: [
13
+ /* @__PURE__ */ jsx(
14
+ Switch.Root,
15
+ {
16
+ ...otherProps,
17
+ value,
18
+ uncheckedValue,
19
+ className: cn(
20
+ "flex",
21
+ "h-5",
22
+ "w-9",
23
+ "shrink-0",
24
+ "p-0.5",
25
+ "transition-colors",
26
+ "duration-150",
27
+ "ease-[ease]",
28
+ "focus-visible:outline-2",
29
+ "focus-visible:outline-offset-2",
30
+ className
31
+ ),
32
+ children: /* @__PURE__ */ jsx(
33
+ Switch.Thumb,
34
+ {
35
+ className: cn(
36
+ "size-3.5",
37
+ "transition-[translate,background-color]",
38
+ "duration-150",
39
+ "ease-[ease]",
40
+ "data-checked:translate-x-4"
41
+ ),
42
+ render: renderThumb
43
+ }
44
+ )
45
+ }
46
+ ),
47
+ label
48
+ ] });
49
+ var BaseSwitch_default = BaseSwitch;
50
+ export {
51
+ BaseSwitch_default as default
52
+ };
@@ -2,9 +2,8 @@ export { default as BaseInput } from './BaseInput.js';
2
2
  export { default as BaseForm } from './BaseForm.js';
3
3
  export { default as BaseFormField } from './BaseFormField.js';
4
4
  import 'react';
5
- import '@base-ui/react/input';
6
- import '../elements/JustDiv.js';
5
+ import '../elements/JustInput.js';
7
6
  import '@base-ui/react/use-render';
7
+ import '../elements/JustDiv.js';
8
8
  import '@base-ui/react/field';
9
- import '../elements/JustInput.js';
10
9
  import 'zod';
@@ -1,3 +1,3 @@
1
- declare function getDirtyFormData(form: HTMLFormElement): FormData;
1
+ declare function getDirtyFormData(form: HTMLFormElement, defaultValues: Record<string, unknown>): FormData;
2
2
 
3
3
  export { getDirtyFormData };
@@ -1,18 +1,33 @@
1
- function isDirty(el) {
1
+ function getCurrentValue(el) {
2
2
  if (el instanceof HTMLSelectElement) {
3
- return Array.from(el.options).filter((o) => o.selected).map((o) => o.value).join(",") !== Array.from(el.options).filter((o) => o.defaultSelected).map((o) => o.value).join(",");
3
+ return Array.from(el.options).filter((o) => o.selected).map((o) => o.value).join(",");
4
4
  }
5
5
  if (el.type === "checkbox" || el.type === "radio") {
6
- return el.checked !== el.defaultChecked;
6
+ return el.checked;
7
7
  }
8
- return el.value !== el.defaultValue;
8
+ return el.value;
9
9
  }
10
- function getDirtyFormData(form) {
10
+ function isDirty(defaultValue, currentValue) {
11
+ switch (typeof defaultValue) {
12
+ case "undefined":
13
+ return currentValue !== "";
14
+ case "string":
15
+ case "boolean":
16
+ return defaultValue !== currentValue;
17
+ case "bigint":
18
+ case "number":
19
+ case "object":
20
+ return JSON.stringify(defaultValue) !== currentValue;
21
+ default:
22
+ return true;
23
+ }
24
+ }
25
+ function getDirtyFormData(form, defaultValues) {
11
26
  const dirty = new FormData();
12
27
  for (const e of Array.from(form.elements)) {
13
28
  if (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement || e instanceof HTMLSelectElement) {
14
29
  if (!e.name) continue;
15
- if (isDirty(e)) {
30
+ if (isDirty(defaultValues[e.name], getCurrentValue(e))) {
16
31
  if (e.type === "checkbox" || e.type === "radio") {
17
32
  if (e.checked) {
18
33
  dirty.append(e.name, e.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/tailwind-ui-kit",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
4
4
  "description": "Tailwind CSS-based React component library for building user interfaces",
5
5
  "keywords": [
6
6
  "tailwind",