letalkui 0.0.2 → 0.0.4

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/.editorconfig ADDED
@@ -0,0 +1,11 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = tab
5
+ indent_size = 4
6
+ # LF (Line Feed) and CRLF (Carriage Return + Line Feed) are different line-ending conventions used to mark the end of a line in text files:
7
+ # More information in this post: https://medium.com/@feldy7k/understanding-line-break-types-cr-lf-and-crlf-278069b8da29
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
@@ -0,0 +1,33 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - master
5
+
6
+ pull_request:
7
+
8
+ workflow_dispatch:
9
+
10
+ name: Check
11
+
12
+ jobs:
13
+ check:
14
+ name: Check
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v2
20
+
21
+ - name: Setup NodeJS
22
+ uses: actions/setup-node@v1
23
+ with:
24
+ node-version: "18.20.3"
25
+
26
+ - name: Install All Dependencies
27
+ run: npm i -f
28
+
29
+ - name: Build
30
+ env:
31
+ CI: true
32
+ NODE_OPTIONS: --max-old-space-size=4096
33
+ run: npm run build
@@ -0,0 +1,25 @@
1
+ on: pull_request
2
+
3
+ name: Lint
4
+
5
+ jobs:
6
+ check:
7
+ name: Lint
8
+ runs-on: ubuntu-latest
9
+ container:
10
+ image: node:18.20.3
11
+
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Setup NodeJS
17
+ uses: actions/setup-node@v2
18
+ with:
19
+ node-version: "18.20.3"
20
+
21
+ - name: Install packages
22
+ run: npm ci
23
+
24
+ - name: Check Lint
25
+ run: npx eslint 'src/**'
@@ -1,27 +1,36 @@
1
1
  name: Release
2
2
 
3
3
  on:
4
- push:
5
- branches:
6
- - master
4
+ push:
5
+ branches:
6
+ - master
7
7
 
8
8
  jobs:
9
- release:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Checkout
13
- uses: actions/checkout@v3
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
14
16
 
15
- - name: Setup Node.js
16
- uses: actions/setup-node@v3
17
- with:
18
- node-version: "18.20.3"
19
- registry-url: 'https://registry.npmjs.org'
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v3
19
+ with:
20
+ node-version: "18.20.3"
21
+ registry-url: 'https://registry.npmjs.org'
20
22
 
21
- - name: Install dependencies
22
- run: npm i -f
23
+ - name: Install dependencies
24
+ run: npm i -f
23
25
 
24
- - name: Release
25
- run: npm publish
26
- env:
27
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26
+ - name: Bump version
27
+ run: |
28
+ git config --global user.name "github-actions[bot]"
29
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
30
+ npm version patch -m "chore(release): %s"
31
+ git push origin master --follow-tags
32
+
33
+ - name: Release
34
+ run: npm publish
35
+ env:
36
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 14.18.1
package/eslint.config.js CHANGED
@@ -1,28 +1,68 @@
1
- import js from '@eslint/js'
2
- import globals from 'globals'
3
- import reactHooks from 'eslint-plugin-react-hooks'
4
- import reactRefresh from 'eslint-plugin-react-refresh'
5
- import tseslint from 'typescript-eslint'
1
+ import js from "@eslint/js"
2
+ import globals from "globals"
3
+ import reactHooks from "eslint-plugin-react-hooks"
4
+ import reactRefresh from "eslint-plugin-react-refresh"
5
+ import react from "eslint-plugin-react"
6
+ import typescriptEslint from "@typescript-eslint/eslint-plugin"
7
+ import jsxA11Y from "eslint-plugin-jsx-a11y"
8
+ import _import from "eslint-plugin-import"
9
+ import tsParser from "@typescript-eslint/parser"
6
10
 
7
- export default tseslint.config(
8
- { ignores: ['dist'] },
9
- {
10
- extends: [js.configs.recommended, ...tseslint.configs.recommended],
11
- files: ['**/*.{ts,tsx}'],
12
- languageOptions: {
13
- ecmaVersion: 2020,
14
- globals: globals.browser,
11
+ export default [
12
+ {
13
+ ignores: ["dist", ".storybook", "vite.config.ts", "tsup.config.ts"],
15
14
  },
16
- plugins: {
17
- 'react-hooks': reactHooks,
18
- 'react-refresh': reactRefresh,
15
+ js.configs.recommended,
16
+ {
17
+ files: ["**/*.{ts,tsx}"],
18
+ languageOptions: {
19
+ ecmaVersion: 2020,
20
+ sourceType: "module",
21
+ globals: {
22
+ ...globals.browser,
23
+ ...globals.node,
24
+ ...globals.jest,
25
+ },
26
+ parser: tsParser,
27
+ parserOptions: {
28
+ project: "./tsconfig.eslint.json",
29
+ ecmaFeatures: {
30
+ jsx: true,
31
+ },
32
+ },
33
+ },
34
+ plugins: {
35
+ "react-hooks": reactHooks,
36
+ "react-refresh": reactRefresh,
37
+ react,
38
+ "@typescript-eslint": typescriptEslint,
39
+ "jsx-a11y": jsxA11Y,
40
+ import: _import,
41
+ },
42
+ rules: {
43
+ ...reactHooks.configs.recommended.rules,
44
+ "react-refresh/only-export-components": [
45
+ "warn",
46
+ { allowConstantExport: true },
47
+ ],
48
+ ...typescriptEslint.configs.recommended.rules,
49
+ ...react.configs.recommended.rules,
50
+ "@typescript-eslint/no-unused-vars": "error",
51
+ indent: ["error", "tab"],
52
+ quotes: ["error", "double"],
53
+ semi: ["error", "never"],
54
+ "object-curly-spacing": ["error", "always"],
55
+ "comma-dangle": ["error", "never"]
56
+ },
57
+ settings: {
58
+ "import/resolver": {
59
+ typescript: {
60
+ project: ["./tsconfig.json"],
61
+ },
62
+ },
63
+ react: {
64
+ version: "detect",
65
+ },
66
+ },
19
67
  },
20
- rules: {
21
- ...reactHooks.configs.recommended.rules,
22
- 'react-refresh/only-export-components': [
23
- 'warn',
24
- { allowConstantExport: true },
25
- ],
26
- },
27
- },
28
- )
68
+ ]
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "letalkui",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
+ "type": "module",
5
6
  "scripts": {
6
7
  "lint": "eslint .",
7
8
  "dev": "storybook dev -p 6006",
@@ -9,10 +10,16 @@
9
10
  "build:storybook": "storybook build"
10
11
  },
11
12
  "dependencies": {
13
+ "@emotion/react": "^11.14.0",
14
+ "@emotion/styled": "^11.14.0",
15
+ "@mui/material": "^6.4.3",
12
16
  "react": "^18.3.1",
17
+ "react-ace": "^10.1.0",
13
18
  "react-dom": "^18.3.1"
14
19
  },
15
20
  "devDependencies": {
21
+ "@eslint/compat": "^1.2.5",
22
+ "@eslint/eslintrc": "^3.2.0",
16
23
  "@eslint/js": "^9.17.0",
17
24
  "@storybook/addon-essentials": "^8.4.7",
18
25
  "@storybook/blocks": "^8.4.7",
@@ -22,8 +29,13 @@
22
29
  "@types/node": "18.19",
23
30
  "@types/react": "^18.3.18",
24
31
  "@types/react-dom": "^18.3.5",
32
+ "@typescript-eslint/eslint-plugin": "^8.20.0",
33
+ "@typescript-eslint/parser": "^8.20.0",
25
34
  "@vitejs/plugin-react-swc": "^3.5.0",
26
35
  "eslint": "^9.17.0",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "eslint-plugin-jsx-a11y": "^6.10.2",
38
+ "eslint-plugin-react": "^7.37.4",
27
39
  "eslint-plugin-react-hooks": "^5.0.0",
28
40
  "eslint-plugin-react-refresh": "^0.4.16",
29
41
  "eslint-plugin-storybook": "^0.11.2",
@@ -0,0 +1,35 @@
1
+ import React from "react"
2
+
3
+ import {
4
+ Button,
5
+ CircularProgress
6
+ } from "@mui/material"
7
+
8
+ type ActionButtonProps = {
9
+ onSave: () => void
10
+ loading: boolean
11
+ }
12
+
13
+ export const ActionButton: React.FC<ActionButtonProps> = (props) => {
14
+ const {
15
+ onSave,
16
+ loading
17
+ } = props
18
+
19
+ const handleSave = () => {
20
+ onSave()
21
+ }
22
+
23
+ return (
24
+ <Button
25
+ onClick={handleSave}
26
+ color="primary"
27
+ variant="contained"
28
+ disableElevation
29
+ disabled={loading}
30
+ endIcon={loading && <CircularProgress size={20} color="inherit" />}
31
+ >
32
+ Salvar
33
+ </Button>
34
+ )
35
+ }
@@ -0,0 +1,23 @@
1
+ import React from "react"
2
+ import {
3
+ Grid2 as Grid
4
+ } from "@mui/material"
5
+
6
+ type ActionsButtonsProps = {
7
+ children: React.ReactNode
8
+ }
9
+
10
+ export const ActionsButtons: React.FC<ActionsButtonsProps> = (props) => {
11
+ return (
12
+ <Grid
13
+ container
14
+ justify="flex-end"
15
+ >
16
+ <Grid
17
+ item
18
+ >
19
+ {props.children}
20
+ </Grid>
21
+ </Grid>
22
+ )
23
+ }
@@ -0,0 +1,67 @@
1
+ import React from "react"
2
+ import AceEditor, { IAceEditorProps } from "react-ace"
3
+ import {
4
+ FormControl,
5
+ FormHelperText,
6
+ Grid2 as Grid
7
+ } from "@mui/material"
8
+
9
+ export type JsonValue = Record<string | number, unknown>
10
+
11
+ export type Overwrite<T, NewT> = Omit<T, keyof NewT> & NewT;
12
+
13
+ export type ContentProps = Overwrite<IAceEditorProps, {
14
+ value?: JsonValue | null
15
+ onChange?: (updatedJson: string) => void
16
+ currentError?: boolean
17
+ currentHelperText?: string
18
+ }>
19
+
20
+ const INPUT_NAME = "json-editor"
21
+
22
+ export const Content: React.FC<ContentProps> = (props) => {
23
+ const {
24
+ value,
25
+ onChange,
26
+ currentError,
27
+ currentHelperText,
28
+ ...rest
29
+ } = props
30
+
31
+ const stringifyValue = JSON.stringify(value, null, 2)
32
+
33
+ return (
34
+ <Grid>
35
+ <FormControl
36
+ error={currentError}
37
+ fullWidth
38
+ >
39
+ <AceEditor
40
+ {...rest}
41
+ name={INPUT_NAME}
42
+ value={stringifyValue}
43
+ wrapEnabled={true}
44
+ mode="json"
45
+ theme="textmate"
46
+ onChange={onChange}
47
+ fontSize={16}
48
+ showPrintMargin={true}
49
+ showGutter={true}
50
+ highlightActiveLine={true}
51
+ editorProps={{ $blockScrolling: true }}
52
+ setOptions={{
53
+ showLineNumbers: true,
54
+ tabSize: 2
55
+ }}
56
+ />
57
+ </FormControl>
58
+ {currentHelperText && (
59
+ <FormHelperText
60
+ error={currentError}
61
+ >
62
+ {currentHelperText}
63
+ </FormHelperText>
64
+ )}
65
+ </Grid>
66
+ )
67
+ }
@@ -0,0 +1,21 @@
1
+ import React from "react"
2
+
3
+ import {
4
+ Grid2 as Grid
5
+ } from "@mui/material"
6
+
7
+ type RootProps = {
8
+ children: React.ReactNode
9
+ }
10
+
11
+ export const Root: React.FC<RootProps> = (props) => {
12
+ return (
13
+ <Grid
14
+ container
15
+ direction="column"
16
+ spacing={2}
17
+ >
18
+ {props.children}
19
+ </Grid>
20
+ )
21
+ }
@@ -0,0 +1,11 @@
1
+ import { Root } from "@/componentPatterns/JsonForm/Root"
2
+ import { ActionButton } from "@/componentPatterns/JsonForm/ActionButton"
3
+ import { ActionsButtons } from "@/componentPatterns/JsonForm/ActionsButtons"
4
+ import { Content } from "@/componentPatterns/JsonForm/Content"
5
+
6
+ export const JsonForm = {
7
+ Root,
8
+ ActionButton,
9
+ ActionsButtons,
10
+ Content
11
+ }
@@ -1,53 +1,53 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { fn } from '@storybook/test';
3
-
4
- import { Button } from '.';
5
-
6
- // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
7
- const meta = {
8
- title: 'Example/Button',
9
- component: Button,
10
- parameters: {
11
- // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
12
- layout: 'centered',
13
- },
14
- // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
15
- tags: ['autodocs'],
16
- // More on argTypes: https://storybook.js.org/docs/api/argtypes
17
- argTypes: {
18
- backgroundColor: { control: 'color' },
19
- },
20
- // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
21
- args: { onClick: fn() },
22
- } satisfies Meta<typeof Button>;
23
-
24
- export default meta;
25
- type Story = StoryObj<typeof meta>;
26
-
27
- // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
1
+ import type { Meta, StoryObj } from "@storybook/react"
2
+ import { fn } from "@storybook/test"
3
+
4
+ import { Button } from "@/components/Button"
5
+
6
+ const meta: Meta<typeof Button> = {
7
+ title: "Example/Button",
8
+ component: Button,
9
+ parameters: {
10
+ layout: "centered"
11
+ },
12
+ tags: ["autodocs"],
13
+ argTypes: {
14
+ backgroundColor: {
15
+ control: "color"
16
+ }
17
+ },
18
+ args: {
19
+ onClick: fn()
20
+ }
21
+ }
22
+
23
+ export default meta
24
+
25
+ type Story = StoryObj<typeof meta>
26
+
28
27
  export const Primary: Story = {
29
- args: {
30
- primary: true,
31
- label: 'Button',
32
- },
33
- };
28
+ args: {
29
+ primary: true,
30
+ label: "Button",
31
+ size: "large"
32
+ }
33
+ }
34
34
 
35
35
  export const Secondary: Story = {
36
- args: {
37
- label: 'Button',
38
- },
39
- };
36
+ args: {
37
+ label: "Button"
38
+ }
39
+ }
40
40
 
41
41
  export const Large: Story = {
42
- args: {
43
- size: 'large',
44
- label: 'Button',
45
- },
46
- };
42
+ args: {
43
+ size: "large",
44
+ label: "Button"
45
+ }
46
+ }
47
47
 
48
48
  export const Small: Story = {
49
- args: {
50
- size: 'small',
51
- label: 'Button',
52
- },
53
- };
49
+ args: {
50
+ size: "small",
51
+ label: "Button"
52
+ }
53
+ }
@@ -1,35 +1,30 @@
1
- import React from 'react';
1
+ import React from "react"
2
2
 
3
3
  export interface ButtonProps {
4
- /** Is this the principal call to action on the page? */
5
- primary?: boolean;
6
- /** What background color to use */
7
- backgroundColor?: string;
8
- /** How large should the button be? */
9
- size?: 'small' | 'medium' | 'large';
10
- /** Button contents */
11
- label: string;
12
- /** Optional click handler */
13
- onClick?: () => void;
4
+ primary?: boolean
5
+ backgroundColor?: string
6
+ size?: "small" | "medium" | "large"
7
+ label: string
8
+ onClick?: () => void
14
9
  }
15
10
 
16
- /** Primary UI component for user interaction */
17
- export const Button = ({
18
- primary = false,
19
- size = 'medium',
20
- backgroundColor,
21
- label,
22
- ...props
23
- }: ButtonProps) => {
24
- const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
25
- return (
26
- <button
27
- type="button"
28
- className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
29
- style={{ backgroundColor }}
30
- {...props}
31
- >
32
- {label}
33
- </button>
34
- );
35
- };
11
+ export const Button = (props: ButtonProps) => {
12
+ const {
13
+ backgroundColor,
14
+ label,
15
+ size,
16
+ primary
17
+ } = props
18
+
19
+ const mode = primary ? "storybook-button--primary" : "storybook-button--secondary"
20
+ return (
21
+ <button
22
+ type="button"
23
+ className={["storybook-button", `storybook-button--${size}`, mode].join("")}
24
+ style={{ backgroundColor }}
25
+ {...props}
26
+ >
27
+ {label}
28
+ </button>
29
+ )
30
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ Meta,
3
+ StoryObj
4
+ } from "@storybook/react"
5
+
6
+ import { JsonEditor } from "@/components/JsonEditor"
7
+
8
+ const meta: Meta<typeof JsonEditor> = {
9
+ title: "Example/JsonEditor",
10
+ component: JsonEditor,
11
+ parameters: {
12
+ layout: "centered"
13
+ },
14
+ tags: ["autodocs"],
15
+ argTypes: {
16
+ value: {
17
+ type: "string"
18
+ }
19
+ }
20
+ }
21
+
22
+ export default meta
23
+
24
+ type Story = StoryObj<typeof meta>
25
+
26
+ export const Primary: Story = {
27
+ args: {
28
+ value: {
29
+ "id": 1,
30
+ "nome": "dsadsa",
31
+ "ativo": true,
32
+ "dataCriacao": "2025-02-07T12:00:00.000Z",
33
+
34
+ "itens": [{
35
+ "id": 101,
36
+ "descricao": "Item 1",
37
+ "quantidade": 10,
38
+ "preco": 19.99
39
+ }, {
40
+ "id": 102,
41
+ "descricao": "Item 2",
42
+ "quantidade": 5,
43
+ "preco": 49.99
44
+ }]
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,84 @@
1
+ import React, { useState } from "react"
2
+ import { IAceEditorProps } from "react-ace"
3
+
4
+ import { JsonForm } from "@/componentPatterns/JsonForm"
5
+ import {
6
+ JsonValue,
7
+ Overwrite
8
+ } from "@/componentPatterns/JsonForm/Content"
9
+
10
+ import useValidation from "@/hooks/useValidation"
11
+
12
+ type JsonEditorProps = Overwrite<IAceEditorProps, {
13
+ value?: JsonValue | null
14
+ onChange?: (value: string) => void
15
+ onSave?: (value: JsonValue) => Promise<JsonValue>
16
+ helperText?: string
17
+ error?: boolean
18
+ }>
19
+
20
+ const INPUT_NAME = "json-editor"
21
+
22
+ export const JsonEditor: React.FC<JsonEditorProps> = (props) => {
23
+ const {
24
+ value,
25
+ onChange,
26
+ onSave,
27
+ helperText,
28
+ error,
29
+ ...rest
30
+ } = props
31
+
32
+ const { addValidation, clearValidation, validation } = useValidation()
33
+
34
+ const stringifyValue = JSON.stringify(value, null, 2)
35
+
36
+ const [jsonData, setJsonData] = useState<string>(stringifyValue)
37
+ const [loadingSaveJson, setLoadingSaveJson] = useState<boolean>(false)
38
+
39
+ const currentError: boolean = validation[INPUT_NAME] ?? error
40
+ const currentHelperText: string = validation[INPUT_NAME] ?? helperText
41
+
42
+ const handleChange = (newValue: string) => {
43
+ clearValidation(INPUT_NAME)
44
+
45
+ setJsonData(newValue)
46
+
47
+ onChange?.(newValue)
48
+ }
49
+
50
+ const handleSave = async () => {
51
+ setLoadingSaveJson(true)
52
+
53
+ if (onSave) {
54
+ try {
55
+ const parseJsonData = JSON.parse(jsonData)
56
+
57
+ await onSave(parseJsonData)
58
+ } catch (error) {
59
+ addValidation({ [INPUT_NAME]: error })
60
+ }
61
+ }
62
+
63
+ setLoadingSaveJson(false)
64
+ }
65
+
66
+ return (
67
+ <JsonForm.Root>
68
+ <JsonForm.Content
69
+ {...rest}
70
+ value={value}
71
+ onChange={handleChange}
72
+ currentError={currentError}
73
+ currentHelperText={currentHelperText}
74
+ />
75
+
76
+ <JsonForm.ActionsButtons>
77
+ <JsonForm.ActionButton
78
+ onSave={handleSave}
79
+ loading={loadingSaveJson}
80
+ />
81
+ </JsonForm.ActionsButtons>
82
+ </JsonForm.Root>
83
+ )
84
+ }
@@ -0,0 +1,42 @@
1
+ import type {
2
+ Meta,
3
+ StoryObj
4
+ } from "@storybook/react"
5
+
6
+ import { JsonView } from "@/components/JsonView"
7
+
8
+ const meta: Meta<typeof JsonView> = {
9
+ title: "Example/JsonView",
10
+ component: JsonView,
11
+ parameters: {
12
+ layout: "centered"
13
+ },
14
+ tags: ["autodocs"]
15
+ }
16
+
17
+ export default meta
18
+
19
+ type Story = StoryObj<typeof meta>
20
+
21
+ export const Primary: Story = {
22
+ args: {
23
+ value: {
24
+ "id": 1,
25
+ "nome": "dsadsa",
26
+ "ativo": true,
27
+ "dataCriacao": "2025-02-07T12:00:00.000Z",
28
+
29
+ "itens": [{
30
+ "id": 101,
31
+ "descricao": "Item 1",
32
+ "quantidade": 10,
33
+ "preco": 19.99
34
+ }, {
35
+ "id": 102,
36
+ "descricao": "Item 2",
37
+ "quantidade": 5,
38
+ "preco": 49.99
39
+ }]
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,29 @@
1
+ import React from "react"
2
+ import { IAceEditorProps } from "react-ace"
3
+
4
+ import { JsonForm } from "@/componentPatterns/JsonForm"
5
+
6
+ import {
7
+ JsonValue,
8
+ Overwrite
9
+ } from "@/componentPatterns/JsonForm/Content"
10
+
11
+ type JsonViewProps = Overwrite<IAceEditorProps, {
12
+ value?: JsonValue | null
13
+ }>
14
+
15
+ export const JsonView: React.FC<JsonViewProps> = (props) => {
16
+ const {
17
+ value,
18
+ ...rest
19
+ } = props
20
+
21
+ return (
22
+ <JsonForm.Root>
23
+ <JsonForm.Content
24
+ {...rest}
25
+ value={value}
26
+ />
27
+ </JsonForm.Root>
28
+ )
29
+ }
@@ -0,0 +1,39 @@
1
+ import { useState } from "react"
2
+
3
+ export type ValidationType = Record<string, unknown>
4
+
5
+ const useValidation = () => {
6
+ const [validation, setValidation] = useState<ValidationType>({})
7
+
8
+ const addValidation = (newValidation: ValidationType) => {
9
+ setValidation((lastValidation) => ({
10
+ ...lastValidation,
11
+ ...newValidation
12
+ }))
13
+ }
14
+
15
+ const clearValidation = (key: string) => {
16
+ if (key in validation) {
17
+ setValidation((lastValidation) => {
18
+ const updatedData: ValidationType = { ...lastValidation }
19
+
20
+ delete updatedData[key]
21
+
22
+ return updatedData
23
+ })
24
+ }
25
+ }
26
+
27
+ const clearAllValidations = () => {
28
+ setValidation({})
29
+ }
30
+
31
+ return {
32
+ addValidation,
33
+ clearValidation,
34
+ clearAllValidations,
35
+ validation
36
+ }
37
+ }
38
+
39
+ export default useValidation
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./components/Button"
1
+ export * from "@/components/Button"
package/tsconfig.app.json CHANGED
@@ -24,7 +24,8 @@
24
24
  "baseUrl": ".",
25
25
  "paths": {
26
26
  "@/*": ["src/*"]
27
- }
27
+ },
28
+ "allowSyntheticDefaultImports": true
28
29
  },
29
30
  "include": ["src"]
30
31
  }
@@ -3,8 +3,9 @@
3
3
  "jsx": "react-jsx",
4
4
  "target": "ES2022",
5
5
  "esModuleInterop": true,
6
- "strict": true,
7
- "module": "NodeNext",
6
+ "moduleResolution": "node",
7
+ "strict": true,
8
+ "module": "ESNext",
8
9
  "sourceMap": true,
9
10
  "declaration": true,
10
11
  "lib": ["ES2022", "DOM", "DOM.Iterable"],
@@ -14,4 +15,4 @@
14
15
  }
15
16
  },
16
17
  "include": ["src"]
17
- }
18
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.stories.ts"]
4
+ }