@twintag/twintag-form 1.4.1 → 1.6.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.
Files changed (47) hide show
  1. package/.turbo/turbo-build.log +16 -15
  2. package/CHANGELOG.md +12 -0
  3. package/dev/main.tsx +1 -1
  4. package/dist/common/button.d.ts +5 -86
  5. package/dist/common/calendar.d.ts +3 -81
  6. package/dist/common/form.d.ts +14 -94
  7. package/dist/common/input.d.ts +10 -155
  8. package/dist/common/label.d.ts +2 -23
  9. package/dist/common/textarea.d.ts +5 -78
  10. package/dist/components/containers/accordion.d.ts +1 -1
  11. package/dist/components/fields/date-picker.d.ts +1 -2
  12. package/dist/components/form.d.ts +2 -2
  13. package/dist/components/provider.d.ts +8 -10
  14. package/dist/index.cjs +1 -0
  15. package/dist/index.js +4456 -0
  16. package/dist/types/index.d.ts +1 -1
  17. package/dist/webcomponent.cjs +1 -0
  18. package/dist/webcomponent.js +1170 -0
  19. package/lib/common/calendar.tsx +1 -1
  20. package/lib/common/form.tsx +1 -1
  21. package/lib/common/input.tsx +1 -1
  22. package/lib/common/textarea.tsx +1 -1
  23. package/lib/components/containers/accordion.tsx +3 -3
  24. package/lib/components/containers/category.tsx +1 -1
  25. package/lib/components/fields/checkbox.tsx +1 -1
  26. package/lib/components/fields/date-picker.tsx +4 -4
  27. package/lib/components/fields/file.tsx +1 -1
  28. package/lib/components/fields/input.tsx +1 -1
  29. package/lib/components/fields/radiogroup.tsx +2 -2
  30. package/lib/components/fields/textarea.tsx +1 -1
  31. package/lib/components/fields/toggle.tsx +1 -1
  32. package/lib/types/index.ts +1 -1
  33. package/lib/utils/data.ts +5 -3
  34. package/lib/utils/string.ts +3 -3
  35. package/lib/webcomponent.ts +0 -1
  36. package/package.json +8 -12
  37. package/tailwind.config.ts +2 -2
  38. package/tsconfig.json +5 -4
  39. package/vite.config.ts +18 -10
  40. package/.eslintrc.cjs +0 -9
  41. package/dist/common/scroll-area.d.ts +0 -5
  42. package/dist/common/select.d.ts +0 -13
  43. package/dist/react.d.ts +0 -1
  44. package/dist/twintag-form.react.js +0 -22652
  45. package/dist/twintag-form.webcomponent.js +0 -4758
  46. package/lib/common/scroll-area.tsx +0 -46
  47. package/lib/common/select.tsx +0 -159
@@ -1,6 +1,6 @@
1
+ import type * as React from 'react';
1
2
  import type { VariantProps } from 'tailwind-variants';
2
3
 
3
- import * as React from 'react';
4
4
  import { ChevronLeft, ChevronRight } from 'lucide-react';
5
5
  import { DayPicker } from 'react-day-picker';
6
6
  import { tv } from 'tailwind-variants';
@@ -70,7 +70,7 @@ const formItemVariants = tv({
70
70
  variants: {
71
71
  variant: {
72
72
  default: 'space-y-2',
73
- beta: 'space-y-1',
73
+ outline: 'space-y-1',
74
74
  },
75
75
  },
76
76
  defaultVariants: {
@@ -18,7 +18,7 @@ const inputVariants = tv({
18
18
  input:
19
19
  'rounded-md border px-3 ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
20
20
  },
21
- beta: {
21
+ outline: {
22
22
  root: 'after:absolute after:left-0 after:top-[calc(100%_+_1px)] after:w-full after:rounded-full after:content-[""] focus-within:after:h-0.5 focus-within:after:bg-ring',
23
23
  input: 'border-b px-1',
24
24
  },
@@ -17,7 +17,7 @@ const textareaVariants = tv({
17
17
  textarea:
18
18
  'rounded-md border px-3 ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
19
19
  },
20
- beta: {
20
+ outline: {
21
21
  root: 'after:absolute after:left-0 after:top-[calc(100%_+_1px)] after:w-full after:rounded-full after:content-[""] focus-within:after:h-0.5 focus-within:after:bg-ring',
22
22
  textarea: 'border-b px-1',
23
23
  },
@@ -1,7 +1,7 @@
1
+ import type { FC } from 'react';
1
2
  import type { Props } from '@twintag/twintag-form/types';
2
3
  import type { WithChildren } from 'twintag-types/dom';
3
4
 
4
- import { type FC } from 'react';
5
5
  import { tv } from 'tailwind-variants';
6
6
 
7
7
  import {
@@ -24,7 +24,7 @@ const accordionRootVariants = tv({
24
24
  variants: {
25
25
  variant: {
26
26
  default: 'rounded-md',
27
- beta: 'rounded-none',
27
+ outline: 'rounded-none',
28
28
  },
29
29
  },
30
30
  defaultVariants: {
@@ -66,7 +66,7 @@ const accordionItemVariants = tv({
66
66
  default: {
67
67
  trigger: 'font-medium',
68
68
  },
69
- beta: {
69
+ outline: {
70
70
  trigger: '',
71
71
  },
72
72
  },
@@ -16,7 +16,7 @@ const categoryStyle = tv({
16
16
  default: {
17
17
  heading: 'font-medium',
18
18
  },
19
- beta: {
19
+ outline: {
20
20
  heading: 'font-normal',
21
21
  },
22
22
  },
@@ -29,7 +29,7 @@ export const Checkbox: FC<Props<'input'>> = ({ label, bind, options }) => {
29
29
  control={control}
30
30
  name={bind}
31
31
  rules={{
32
- required: isOptional ? false : options?.error ?? true,
32
+ required: isOptional ? false : (options?.error ?? true),
33
33
  }}
34
34
  render={({ field }) => (
35
35
  <FormItem variant={variant} className='pt-1.5'>
@@ -1,6 +1,6 @@
1
+ import type * as React from 'react';
1
2
  import type { Props } from '@twintag/twintag-form/types';
2
3
 
3
- import * as React from 'react';
4
4
  import { format } from 'date-fns';
5
5
  import { AsteriskIcon, Calendar as CalendarIcon } from 'lucide-react';
6
6
  import { useFormContext } from 'react-hook-form';
@@ -33,7 +33,7 @@ const datePickerTriggerVariants = tv({
33
33
  default: {
34
34
  button: 'px-3',
35
35
  },
36
- beta: {
36
+ outline: {
37
37
  button:
38
38
  'rounded-none border-x-transparent border-t-transparent px-1 transition-none hover:bg-white hover:text-muted-foreground',
39
39
  },
@@ -83,7 +83,7 @@ export const DatePicker: React.FC<Props<'input'>> = ({
83
83
  control={control}
84
84
  name={bind}
85
85
  rules={{
86
- required: isOptional ? false : options?.error ?? true,
86
+ required: isOptional ? false : (options?.error ?? true),
87
87
  }}
88
88
  render={({ field }) => (
89
89
  <FormItem
@@ -137,7 +137,7 @@ export const DatePicker: React.FC<Props<'input'>> = ({
137
137
  mode='single'
138
138
  size={size}
139
139
  selected={
140
- !isNaN(new Date(field.value as Date).getTime())
140
+ !Number.isNaN(new Date(field.value as Date).getTime())
141
141
  ? new Date(field.value as Date)
142
142
  : undefined
143
143
  }
@@ -29,7 +29,7 @@ export const File: FC<Props<'input'>> = ({ label, bind, options }) => {
29
29
  control={control}
30
30
  name={bind}
31
31
  rules={{
32
- required: isOptional ? false : options?.error ?? true,
32
+ required: isOptional ? false : (options?.error ?? true),
33
33
  }}
34
34
  render={({ field, formState }) => (
35
35
  <FormItem variant={variant}>
@@ -30,7 +30,7 @@ export const Input: FC<Props<'input'>> = ({ label, bind, options }) => {
30
30
  control={control}
31
31
  name={bind}
32
32
  rules={{
33
- required: isOptional ? false : options?.error ?? true,
33
+ required: isOptional ? false : (options?.error ?? true),
34
34
  }}
35
35
  render={({ field }) => (
36
36
  <FormItem variant={variant}>
@@ -36,7 +36,7 @@ export const RadioGroup: FC<
36
36
  control={control}
37
37
  name={bind}
38
38
  rules={{
39
- required: isOptional ? false : options?.error ?? true,
39
+ required: isOptional ? false : (options?.error ?? true),
40
40
  }}
41
41
  render={({ field }) => (
42
42
  <FormItem className='space-y-3'>
@@ -82,7 +82,7 @@ export const RadioGroup: FC<
82
82
  );
83
83
  }
84
84
 
85
- return <></>;
85
+ return null;
86
86
  })}
87
87
  </CommonRadioGroup>
88
88
  </FormControl>
@@ -29,7 +29,7 @@ export const Textarea: FC<Props<'input'>> = ({ label, bind, options }) => {
29
29
  control={control}
30
30
  name={bind}
31
31
  rules={{
32
- required: isOptional ? false : options?.error ?? true,
32
+ required: isOptional ? false : (options?.error ?? true),
33
33
  }}
34
34
  render={({ field }) => (
35
35
  <FormItem variant={variant}>
@@ -29,7 +29,7 @@ export const Toggle: FC<Props<'input'>> = ({ label, bind, options }) => {
29
29
  control={control}
30
30
  name={bind}
31
31
  rules={{
32
- required: isOptional ? false : options?.error ?? true,
32
+ required: isOptional ? false : (options?.error ?? true),
33
33
  }}
34
34
  render={({ field }) => (
35
35
  <FormItem variant={variant}>
@@ -73,7 +73,7 @@ export type Props<
73
73
  };
74
74
 
75
75
  export type TwintagFormContext = {
76
- variant?: 'default' | 'beta';
76
+ variant?: 'default' | 'outline';
77
77
  size?: 'base' | 'sm';
78
78
  inputs: Map<string, InputCompConfig>;
79
79
  components: Map<string, ElementType>;
package/lib/utils/data.ts CHANGED
@@ -6,16 +6,18 @@ type Items = (Props<'input'> & {
6
6
  export const getBindSetFromItems = (items: Items): Set<string> => {
7
7
  const binds = new Set<string>();
8
8
 
9
- items.forEach((item) => {
9
+ for (const item of items) {
10
10
  if (item.bind) {
11
11
  binds.add(item.bind);
12
12
  }
13
13
 
14
14
  if (item.items) {
15
15
  const subBinds = getBindSetFromItems(item.items as unknown as Items);
16
- subBinds.forEach((bind) => binds.add(bind));
16
+ for (const bind of subBinds) {
17
+ binds.add(bind);
18
+ }
17
19
  }
18
- });
20
+ }
19
21
 
20
22
  return binds;
21
23
  };
@@ -1,8 +1,8 @@
1
1
  export const camelize = (str: string) => {
2
2
  return str
3
- .replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
4
- return index === 0 ? word.toLowerCase() : word.toUpperCase();
5
- })
3
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) =>
4
+ index === 0 ? word.toLowerCase() : word.toUpperCase(),
5
+ )
6
6
  .replace(/\s+/g, '');
7
7
  };
8
8
 
@@ -8,7 +8,6 @@ import config from '../twind.config';
8
8
  const withTwind = install(config);
9
9
 
10
10
  const TwintagFormElement = r2wc(Form, {
11
- // @ts-expect-error: ts limitation
12
11
  props: {
13
12
  config: 'json',
14
13
  options: 'json',
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@twintag/twintag-form",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "author": "Twintag",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./dist/twintag-form.react.js",
9
- "types": "./dist/react.d.ts"
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.cjs"
10
11
  },
11
12
  "./webcomponent": {
12
- "import": "./dist/twintag-form.webcomponent.js",
13
- "types": "./dist/webcomponent.d.ts"
13
+ "types": "./dist/webcomponent.d.ts",
14
+ "import": "./dist/webcomponent.js",
15
+ "require": "./dist/webcomponent.cjs"
14
16
  }
15
17
  },
16
18
  "dependencies": {
@@ -22,12 +24,9 @@
22
24
  "@radix-ui/react-label": "^2.0.2",
23
25
  "@radix-ui/react-popover": "^1.0.7",
24
26
  "@radix-ui/react-radio-group": "^1.1.3",
25
- "@radix-ui/react-scroll-area": "^1.0.5",
26
- "@radix-ui/react-select": "^2.0.0",
27
27
  "@radix-ui/react-slider": "^1.1.2",
28
28
  "@radix-ui/react-slot": "^1.0.2",
29
29
  "@radix-ui/react-switch": "^1.0.2",
30
- "@storybook/react": "7.0.2",
31
30
  "@twind/core": "^1.1.3",
32
31
  "@twind/preset-autoprefix": "^1.0.7",
33
32
  "@twind/preset-tailwind": "^1.1.4",
@@ -46,12 +45,10 @@
46
45
  "@twind/with-react": "^1.1.3",
47
46
  "@types/uuid": "^9.0.7",
48
47
  "@vitejs/plugin-react-swc": "^3.6.0",
49
- "tailwindcss": "^3.3.6",
50
48
  "vite": "^5.2.11",
51
49
  "vite-plugin-dts": "^3.9.1",
52
- "eslint-config-custom": "1.0.0",
53
50
  "tsconfig": "0.0.0",
54
- "twintag-types": "0.2.0"
51
+ "twintag-types": "0.4.0"
55
52
  },
56
53
  "publishConfig": {
57
54
  "access": "public"
@@ -59,7 +56,6 @@
59
56
  "scripts": {
60
57
  "dev": "vite",
61
58
  "build": "tsc && vite build",
62
- "lint": "eslint . --ext .ts,.tsx",
63
59
  "format": "prettier --write \"**/*.{ts,md,tsx,cjs,mjs,json,html}\" --ignore-path ../../.gitignore",
64
60
  "format:check": "prettier --check \"**/*.{ts,md,tsx,cjs,mjs,json,html}\" --ignore-path ../../.gitignore"
65
61
  }
@@ -34,8 +34,8 @@ const config = {
34
34
  ring: 'hsl(var(--tf-ring) / <alpha-value>)',
35
35
  },
36
36
  borderRadius: {
37
- lg: `var(--tf-radius)`,
38
- md: `calc(var(--tf-radius) - 2px)`,
37
+ lg: 'var(--tf-radius)',
38
+ md: 'calc(var(--tf-radius) - 2px)',
39
39
  sm: 'calc(var(--tf-radius) - 4px)',
40
40
  },
41
41
  fontFamily: {
package/tsconfig.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "extends": "tsconfig/vite.json",
3
3
  "include": [
4
- ".eslintrc.cjs",
5
- "prettier.config.mjs",
6
4
  "lib",
7
5
  "dev",
8
6
  "scripts",
9
7
  "types.d.ts",
10
8
  "tailwind.config.ts",
9
+ "twind.config.ts",
11
10
  "vite.config.ts"
12
11
  ],
13
- "exclude": ["dist", "build", "node_modules"],
12
+ "exclude": ["dist", "build", "node_modules", "prettier.config.mjs"],
14
13
  "compilerOptions": {
15
14
  "baseUrl": ".",
16
15
  "paths": {
@@ -19,8 +18,10 @@
19
18
 
20
19
  /* Bundler mode */
21
20
  "moduleResolution": "bundler",
22
- "declaration": false,
21
+ "declaration": true,
23
22
  "declarationMap": false,
23
+ "moduleDetection": "force",
24
+ "isolatedModules": true,
24
25
 
25
26
  /* Linting */
26
27
  "strict": true,
package/vite.config.ts CHANGED
@@ -1,8 +1,21 @@
1
1
  import react from '@vitejs/plugin-react-swc';
2
- import { resolve } from 'pathe';
2
+ import { dirname, resolve } from 'pathe';
3
3
  import { defineConfig } from 'vite';
4
4
  import dts from 'vite-plugin-dts';
5
5
 
6
+ import { dependencies, devDependencies } from './package.json';
7
+
8
+ export const __dirname = dirname(new URL(import.meta.url).pathname);
9
+
10
+ const externalPackages = [
11
+ ...Object.keys(dependencies || {}),
12
+ ...Object.keys(devDependencies || {}),
13
+ ].filter((packageName) => packageName !== 'twintag-types');
14
+
15
+ const regexesOfPackages = externalPackages.map(
16
+ (packageName) => new RegExp(`^${packageName}(/.*)?`),
17
+ );
18
+
6
19
  // https://vitejs.dev/config/
7
20
  export default defineConfig({
8
21
  resolve: {
@@ -14,21 +27,17 @@ export default defineConfig({
14
27
  lib: {
15
28
  // Could also be a dictionary or array of multiple entry points
16
29
  entry: {
17
- react: resolve(__dirname, './lib/index.tsx'),
30
+ index: resolve(__dirname, './lib/index.tsx'),
18
31
  webcomponent: resolve(__dirname, './lib/webcomponent.ts'),
19
32
  },
20
- name: 'twintag-form',
21
- formats: ['es'],
22
- // the proper extensions will be added
23
- fileName: (_, entryName) => `twintag-form.${entryName}.js`,
24
33
  },
25
34
  rollupOptions: {
26
35
  // make sure to externalize deps that shouldn't be bundled
27
36
  // into your library
28
- external: ['react', 'react-dom'],
37
+ external: regexesOfPackages,
38
+ preserveEntrySignatures: 'strict',
29
39
  output: {
30
- // Provide global variables to use in the UMD build
31
- // for externalized deps
40
+ preserveModules: false,
32
41
  globals: {
33
42
  react: 'React',
34
43
  },
@@ -41,7 +50,6 @@ export default defineConfig({
41
50
  entryRoot: resolve(__dirname, 'lib'),
42
51
  insertTypesEntry: true,
43
52
  staticImport: true,
44
- exclude: ['**/__tests__/**', '**/__stories__/**'],
45
53
  }),
46
54
  ],
47
55
  });
package/.eslintrc.cjs DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['custom'],
4
- parserOptions: {
5
- project: 'tsconfig.json',
6
- tsconfigRootDir: __dirname,
7
- sourceType: 'module',
8
- },
9
- };
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
3
- declare const ScrollArea: React.ForwardRefExoticComponent<Omit<ScrollAreaPrimitive.ScrollAreaProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
- declare const ScrollBar: React.ForwardRefExoticComponent<Omit<ScrollAreaPrimitive.ScrollAreaScrollbarProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
- export { ScrollArea, ScrollBar };
@@ -1,13 +0,0 @@
1
- import * as React from 'react';
2
- import * as SelectPrimitive from '@radix-ui/react-select';
3
- declare const Select: React.FC<SelectPrimitive.SelectProps>;
4
- declare const SelectGroup: React.ForwardRefExoticComponent<SelectPrimitive.SelectGroupProps & React.RefAttributes<HTMLDivElement>>;
5
- declare const SelectValue: React.ForwardRefExoticComponent<SelectPrimitive.SelectValueProps & React.RefAttributes<HTMLSpanElement>>;
6
- declare const SelectTrigger: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
7
- declare const SelectScrollUpButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollUpButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
8
- declare const SelectScrollDownButton: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectScrollDownButtonProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
9
- declare const SelectContent: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
10
- declare const SelectLabel: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectLabelProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
11
- declare const SelectItem: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectItemProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
12
- declare const SelectSeparator: React.ForwardRefExoticComponent<Omit<SelectPrimitive.SelectSeparatorProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
13
- export { Select, SelectGroup, SelectValue, SelectTrigger, SelectContent, SelectLabel, SelectItem, SelectSeparator, SelectScrollUpButton, SelectScrollDownButton, };
package/dist/react.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './index'