diff --git a/.changeset/config.json b/.changeset/config.json index 91b6a95..432b15a 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,11 +1,11 @@ { - "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": [] + "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] } diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 0000000..d8ad12a --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,27 @@ +{ + "extends": ["@commitlint/config-conventional"], + "rules": { + "type-enum": [ + 2, + "always", + [ + "build", + "chore", + "ci", + "config", + "docs", + "feat", + "fix", + "perf", + "refactor", + "revert", + "style", + "test" + ] + ], + "scope-empty": [0], + "subject-empty": [2, "never"], + "subject-case": [2, "always", "lower-case"], + "body-leading-blank": [2, "always"] + } +} diff --git a/.lefthook/commit-msg/commitlint.sh b/.lefthook/commit-msg/commitlint.sh new file mode 100644 index 0000000..ac4a39b --- /dev/null +++ b/.lefthook/commit-msg/commitlint.sh @@ -0,0 +1,6 @@ +# .lefthook/commit-msg/commitlint.sh + +#!/bin/bash + +# Print the commit message +echo $(head -n1 "$1") | bunx commitlint --color diff --git a/.vscode/settings.json b/.vscode/settings.json index 1121718..622000b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,53 +1,43 @@ { - "[css]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[javascript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[javascriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[typescript]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "[typescriptreact]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" - }, - "editor.codeActionsOnSave": { - "source.fixAll": "explicit", - "source.fixAll.eslint": "explicit" - }, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "editor.formatOnPaste": false, - "editor.formatOnSave": true, - "eslint.format.enable": true, - "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"], - "files.encoding": "utf8", - "files.insertFinalNewline": true, - "files.trimTrailingWhitespace": true, - "javascript.preferences.importModuleSpecifier": "non-relative", - "javascript.updateImportsOnFileMove.enabled": "always", - "prettier.useEditorConfig": true, - "search.exclude": { - "**/package-lock.json": true, - "**/pnpm-lock.yaml": true, - ".cache/**": true, - ".git/**": true, - "coverage/**": true, - "dist/**": true, - "generated/**": true, - "node_modules/**": true, - "public/**": true - }, - "tailwindCSS.experimental.classRegex": [ - ["cn"], - ["className\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"], - ["classNams\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"], - ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"], - ["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"] - ], - "typescript.preferences.importModuleSpecifier": "non-relative", - "typescript.suggest.autoImports": true, - "typescript.updateImportsOnFileMove.enabled": "always" + "[css]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascriptreact]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescriptreact]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "editor.codeActionsOnSave": { + "source.fixAll": "explicit", + "source.fixAll.eslint": "explicit" + }, + "editor.defaultFormatter": "biomejs.biome", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "files.encoding": "utf8", + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + "javascript.preferences.importModuleSpecifier": "non-relative", + "javascript.updateImportsOnFileMove.enabled": "always", + "search.exclude": { + "**/package-lock.json": true, + "**/pnpm-lock.yaml": true, + ".cache/**": true, + ".git/**": true, + "coverage/**": true, + "dist/**": true, + "generated/**": true, + "node_modules/**": true, + "public/**": true + }, + "typescript.preferences.importModuleSpecifier": "non-relative", + "typescript.suggest.autoImports": true, + "typescript.updateImportsOnFileMove.enabled": "always" } diff --git a/app.tsx b/app.tsx index d3f3b4c..4d76af1 100644 --- a/app.tsx +++ b/app.tsx @@ -1,32 +1,32 @@ import { - Button, - Combobox, - ComboboxContent, - ComboboxItem, - ComboboxTrigger, - Drawer, - DrawerContent, - DrawerTrigger, - Popover, - PopoverContent, - PopoverTrigger, - Select, - SelectContent, - SelectItem, - SelectTrigger, -} from "@/components"; -import { DrawerClose } from "@/components/drawer/components/drawer-close"; -import { DrawerDescription } from "@/components/drawer/components/drawer-description"; -import { DrawerHeader } from "@/components/drawer/components/drawer-header"; -import { DrawerTitle } from "@/components/drawer/components/drawer-title"; -import React, { useState } from "react"; + Button, + Combobox, + ComboboxContent, + ComboboxItem, + ComboboxTrigger, + Drawer, + DrawerContent, + DrawerTrigger, + Popover, + PopoverContent, + PopoverTrigger, + Select, + SelectContent, + SelectItem, + SelectTrigger, +} from '@/components' +import { DrawerClose } from '@/components/drawer/components/drawer-close' +import { DrawerDescription } from '@/components/drawer/components/drawer-description' +import { DrawerHeader } from '@/components/drawer/components/drawer-header' +import { DrawerTitle } from '@/components/drawer/components/drawer-title' +import React, { useState } from 'react' const App = () => { - const [state, setValue] = useState(""); + const [state, setValue] = useState('') - return ( -
- {/* + return ( +
+ {/* Trigger @@ -45,25 +45,25 @@ const App = () => { Item 2 */} - {/* + {/* Trigger Item Item 2 */} - - Trigger - - X - - Title - Description - - - -
- ); -}; + + Trigger + + X + + Title + Description + + + +
+ ) +} -export { App }; +export { App } diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..7045ba4 --- /dev/null +++ b/biome.json @@ -0,0 +1,34 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "complexity": { + "noStaticOnlyClass": "off", + "noForEach": "off" + }, + "suspicious": { + "noArrayIndexKey": "off" + }, + "a11y": { + "useKeyWithClickEvents": "off", + "noSvgWithoutTitle": "off" + }, + "recommended": true + } + }, + "formatter": { + "lineWidth": 100 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "jsxQuoteStyle": "single", + "quoteProperties": "preserve", + "semicolons": "asNeeded" + } + } +} diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..120de71 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,23 @@ +# lefthook.yml + +commit-msg: + scripts: + "commitlint.sh": + runner: bash + +pre-commit: + commands: + 1_lint_check: + glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" + run: yarn biome check --apply --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again + 2_type_check: + glob: "*.{json,js,ts,tsx}" + run: yarn tsc --noEmit -p ./tsconfig.json + 3_build: + run: yarn next build + +pre-push: + commands: + check: + glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" + run: yarn biome check --no-errors-on-unmatched --files-ignore-unknown=true {push_files} diff --git a/main.tsx b/main.tsx index 021cc96..3430d88 100644 --- a/main.tsx +++ b/main.tsx @@ -8,7 +8,7 @@ import { App } from './app' // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope ReactDOM.createRoot(document.querySelector('#root') as HTMLElement).render( - - - , + + + , ) diff --git a/package.json b/package.json index e6ecc98..4cf36e4 100644 --- a/package.json +++ b/package.json @@ -1,78 +1,89 @@ { - "name": "@renderui/core", - "version": "1.5.5", - "private": false, - "description": "React UI library with highly modular and ready-out-of-the-box components", - "license": "MIT", - "author": "Lovro Žagar", - "type": "module", - "exports": { - ".": { - "import": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" - } - } - }, - "main": "./dist/index.js", - "module": "./dist/index.js", - "types": "./dist/index.d.ts", - "files": [ - "dist" - ], - "scripts": { - "build": "bunchee -m", - "dev": "vite dev" - }, - "dependencies": { - "@radix-ui/react-accordion": "^1.2.0", - "@radix-ui/react-collapsible": "^1.1.0", - "@radix-ui/react-dialog": "^1.1.1", - "@radix-ui/react-navigation-menu": "^1.2.0", - "@radix-ui/react-popover": "^1.1.1", - "@radix-ui/react-portal": "^1.1.1", - "@radix-ui/react-scroll-area": "^1.1.0", - "@radix-ui/react-slider": "^1.2.0", - "@radix-ui/react-slot": "^1.1.0", - "@radix-ui/react-tabs": "^1.1.0", - "@radix-ui/react-toggle": "^1.1.0", - "@radix-ui/react-toggle-group": "^1.1.0", - "@radix-ui/react-tooltip": "^1.1.2", - "@renderui/utils": "^0.2.0", - "@types/react": "npm:types-react@rc", - "@types/react-dom": "npm:types-react-dom@rc", - "cmdk": "^1.0.0", - "next-themes": "^0.3.0", - "react-aria": "^3.33.1", - "react-hotkeys-hook": "^4.5.0", - "sonner": "^1.5.0", - "vaul": "^0.9.1" - }, - "overrides": { - "@types/react": "npm:types-react@rc", - "@types/react-dom": "npm:types-react-dom@rc" - }, - "devDependencies": { - "@changesets/cli": "^2.26.0", - "@vitejs/plugin-react": "4.2.1", - "autoprefixer": "^10.4.17", - "bunchee": "^5.3.2", - "framer-motion": "^11.3.28", - "postcss": "^8.4.35", - "react": "^19.0.0-rc-fb9a90fa48-20240614", - "react-dom": "^19.0.0-rc-fb9a90fa48-20240614", - "tailwindcss": "^3.4.1", - "types-react": "^19.0.0-rc.1", - "types-react-dom": "^19.0.0-rc.1", - "typescript": "^5.5.4", - "vite": "^5.1.4" - }, - "peerDependencies": { - "framer-motion": "^11.3.28", - "react": "^19.0.0-rc-fb9a90fa48-20240614", - "react-dom": "^19.0.0-rc-fb9a90fa48-20240614" - }, - "publishConfig": { - "access": "public" - } + "name": "@renderui/core", + "version": "1.5.5", + "private": false, + "description": "React UI library with highly modular and ready-out-of-the-box components", + "license": "MIT", + "author": "Lovro Žagar", + "type": "module", + "exports": { + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + } + }, + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", + "files": ["dist"], + "scripts": { + "build": "bunchee -m", + "dev": "vite dev", + "commitlint:init": "chmod +x .lefthook/commit-msg/commitlint.sh", + "lefthook:init": "yarn lefthook install", + "type:check": "tsc --noEmit", + "type:coverage": "typescript-coverage-report", + "lint": "yarn @biomejs/biome lint ./src", + "lint:check": "yarn @biomejs/biome check ./src", + "lint:format": "yarn @biomejs/biome format ./src", + "lint:fix": "yarn @biomejs/biome lint --write ./src" + }, + "dependencies": { + "@biomejs/biome": "^1.8.3", + "@radix-ui/react-accordion": "^1.2.0", + "@radix-ui/react-collapsible": "^1.1.0", + "@radix-ui/react-dialog": "^1.1.1", + "@radix-ui/react-navigation-menu": "^1.2.0", + "@radix-ui/react-popover": "^1.1.1", + "@radix-ui/react-portal": "^1.1.1", + "@radix-ui/react-scroll-area": "^1.1.0", + "@radix-ui/react-slider": "^1.2.0", + "@radix-ui/react-slot": "^1.1.0", + "@radix-ui/react-tabs": "^1.1.0", + "@radix-ui/react-toggle": "^1.1.0", + "@radix-ui/react-toggle-group": "^1.1.0", + "@radix-ui/react-tooltip": "^1.1.2", + "@renderui/utils": "^0.2.0", + "@types/react": "yarn:types-react@rc", + "@types/react-dom": "yarn:types-react-dom@rc", + "cmdk": "^1.0.0", + "next-themes": "^0.3.0", + "react-aria": "^3.33.1", + "react-hotkeys-hook": "^4.5.0", + "sonner": "^1.5.0", + "vaul": "^0.9.1" + }, + "overrides": { + "@types/react": "yarn:types-react@rc", + "@types/react-dom": "yarn:types-react-dom@rc" + }, + "devDependencies": { + "@changesets/cli": "^2.26.0", + "@vitejs/plugin-react": "4.2.1", + "@commitlint/cli": "^18.6.1", + "@commitlint/config-conventional": "^18.6.2", + "lefthook": "^1.7.12", + "autoprefixer": "^10.4.17", + "bunchee": "^5.3.2", + "framer-motion": "^11.3.28", + "postcss": "^8.4.35", + "react": "^19.0.0-rc-fb9a90fa48-20240614", + "react-dom": "^19.0.0-rc-fb9a90fa48-20240614", + "tailwindcss": "^3.4.1", + "types-react": "^19.0.0-rc.1", + "types-react-dom": "^19.0.0-rc.1", + "typescript": "^5.5.4", + "typescript-coverage-report": "^1.0.0", + "vite": "^5.1.4" + }, + "peerDependencies": { + "framer-motion": "^11.3.28", + "react": "^19.0.0-rc-fb9a90fa48-20240614", + "react-dom": "^19.0.0-rc-fb9a90fa48-20240614" + }, + "publishConfig": { + "access": "public" + } } diff --git a/postcss.config.js b/postcss.config.js index 393a10f..7b25334 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -1,8 +1,8 @@ const config = { - plugins: { - tailwindcss: {}, - autoprefixer: {}, - }, + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, } export default config diff --git a/src/components/_shared/classes/input-container-classes.ts b/src/components/_shared/classes/input-container-classes.ts index 9bb1ff3..3ec0976 100644 --- a/src/components/_shared/classes/input-container-classes.ts +++ b/src/components/_shared/classes/input-container-classes.ts @@ -1,23 +1,23 @@ import { cva } from '@renderui/utils' const inputContainerClasses = cva( - 'group relative box-border appearance-none h-[40px] min-w-0 flex justify-center whitespace-nowrap rounded text-sm font-medium outline-none transition-[box-shadow,background-color,transform,opacity] duration-fast disabled:cursor-not-allowed disabled:opacity-40 cursor-text items-center gap-2 overflow-hidden text-mode-contrast h-[40px] before:content-[""] before:absolute before:block before:left-0 before:top-0 before:size-full before:rounded-[inherit] before:z-[1] before:ring-ring-color before:ring-offset-0 before:ring-offset-background data-[focus-within=true]:before:ring-[2px] data-[hover=true]:data-[focus-within=true]:before:ring-[2px] data-[hover=true]:before:ring-[1px] data-[invalid=true]:before:ring-destructive before:transition-[box-shadow,background-color,transform,opacity] before:duration-fast', - { - variants: { - variant: { - solid: 'bg-mode-accent dat-[hover=true]:bg-mode-accent/80 before:ring-inset', - outline: - 'ring-mode-accent ring-[2px] ring-inset ring-offset-[0px] data-[hover=true]:bg-mode-accent/10 before:ring-inset', - }, - size: { - xs: 'h-[32px]', - sm: 'h-[36px]', - md: 'h-[40px]', - lg: 'h-[46px]', - xl: 'h-[52px]', - }, - }, - }, + 'group relative box-border appearance-none h-[40px] min-w-0 flex justify-center whitespace-nowrap rounded text-sm font-medium outline-none transition-[box-shadow,background-color,transform,opacity] duration-fast disabled:cursor-not-allowed disabled:opacity-40 cursor-text items-center gap-2 overflow-hidden text-mode-contrast h-[40px] before:content-[""] before:absolute before:block before:left-0 before:top-0 before:size-full before:rounded-[inherit] before:z-[1] before:ring-ring-color before:ring-offset-0 before:ring-offset-background data-[focus-within=true]:before:ring-[2px] data-[hover=true]:data-[focus-within=true]:before:ring-[2px] data-[hover=true]:before:ring-[1px] data-[invalid=true]:before:ring-destructive before:transition-[box-shadow,background-color,transform,opacity] before:duration-fast', + { + variants: { + variant: { + solid: 'bg-mode-accent dat-[hover=true]:bg-mode-accent/80 before:ring-inset', + outline: + 'ring-mode-accent ring-[2px] ring-inset ring-offset-[0px] data-[hover=true]:bg-mode-accent/10 before:ring-inset', + }, + size: { + xs: 'h-[32px]', + sm: 'h-[36px]', + md: 'h-[40px]', + lg: 'h-[46px]', + xl: 'h-[52px]', + }, + }, + }, ) export { inputContainerClasses } diff --git a/src/components/_shared/components/field/field-context/field-context.ts b/src/components/_shared/components/field/field-context/field-context.ts index 02053dc..16a2a85 100644 --- a/src/components/_shared/components/field/field-context/field-context.ts +++ b/src/components/_shared/components/field/field-context/field-context.ts @@ -2,15 +2,15 @@ import { initializeContext } from '@renderui/utils' import React from 'react' const [FieldProvider, useFieldContext] = initializeContext<{ - id: string - error: React.ReactNode + id: string + error: React.ReactNode }>({ - errorMessage: - 'Components using useField must be wrapped in their a <{InputName}Field /> component.', - providerName: 'ToggleGroupProvider', - hookName: 'useField', - name: 'fieldContext', - strict: false, + errorMessage: + 'Components using useField must be wrapped in their a <{InputName}Field /> component.', + providerName: 'ToggleGroupProvider', + hookName: 'useField', + name: 'fieldContext', + strict: false, }) export { FieldProvider, useFieldContext } diff --git a/src/components/_shared/components/field/field-label/field-label.tsx b/src/components/_shared/components/field/field-label/field-label.tsx index becb075..05912d8 100644 --- a/src/components/_shared/components/field/field-label/field-label.tsx +++ b/src/components/_shared/components/field/field-label/field-label.tsx @@ -7,20 +7,20 @@ import { useFieldContext } from '@/components/_shared/components/field/field-con import { Label } from '@/components/label' const FieldLabel = (props) => { - const { children, info, className, ...restProps } = props + const { children, info, className, ...restProps } = props - const { id } = useFieldContext() + const { id } = useFieldContext() - return ( - - ) + return ( + + ) } export { FieldLabel } diff --git a/src/components/_shared/components/field/field-message/field-message.tsx b/src/components/_shared/components/field/field-message/field-message.tsx index 6048678..7169a71 100644 --- a/src/components/_shared/components/field/field-message/field-message.tsx +++ b/src/components/_shared/components/field/field-message/field-message.tsx @@ -6,27 +6,27 @@ import React from 'react' import { useFieldContext } from '@/components/_shared/components/field/field-context/field-context' const FieldMessage = (props) => { - const { children } = props + const { children } = props - const { error } = useFieldContext() + const { error } = useFieldContext() - const hasDescription = children !== undefined - const hasError = error !== undefined + const hasDescription = children !== undefined + const hasError = error !== undefined - return ( -
- {error ?? children} -
- ) + return ( +
+ {error ?? children} +
+ ) } export { FieldMessage } diff --git a/src/components/_shared/components/field/field/field.tsx b/src/components/_shared/components/field/field/field.tsx index b915529..276661f 100644 --- a/src/components/_shared/components/field/field/field.tsx +++ b/src/components/_shared/components/field/field/field.tsx @@ -3,15 +3,15 @@ import React from 'react' import { FieldProvider } from '@/components/_shared/components/field/field-context/field-context' const Field = React.forwardRef((props, ref) => { - const { children, error } = props + const { children, error } = props - const id = React.useId() + const id = React.useId() - return ( -
- {children} -
- ) + return ( +
+ {children} +
+ ) }) Field.displayName = 'Field' diff --git a/src/components/_shared/components/icons/caret-sort-icon.tsx b/src/components/_shared/components/icons/caret-sort-icon.tsx index 5751d7f..32ea01d 100644 --- a/src/components/_shared/components/icons/caret-sort-icon.tsx +++ b/src/components/_shared/components/icons/caret-sort-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const CaretSortIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const CaretSortIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { CaretSortIcon }; +export { CaretSortIcon } diff --git a/src/components/_shared/components/icons/check-icon.tsx b/src/components/_shared/components/icons/check-icon.tsx index d97afb1..629b92a 100644 --- a/src/components/_shared/components/icons/check-icon.tsx +++ b/src/components/_shared/components/icons/check-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const CheckIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const CheckIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { CheckIcon }; +export { CheckIcon } diff --git a/src/components/_shared/components/icons/chevron-down-icon.tsx b/src/components/_shared/components/icons/chevron-down-icon.tsx index 18d9dcb..0be6fae 100644 --- a/src/components/_shared/components/icons/chevron-down-icon.tsx +++ b/src/components/_shared/components/icons/chevron-down-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const ChevronDownIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const ChevronDownIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { ChevronDownIcon }; +export { ChevronDownIcon } diff --git a/src/components/_shared/components/icons/chevron-up-icon.tsx b/src/components/_shared/components/icons/chevron-up-icon.tsx index 4c9cd2e..e801abb 100644 --- a/src/components/_shared/components/icons/chevron-up-icon.tsx +++ b/src/components/_shared/components/icons/chevron-up-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const ChevronUpIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const ChevronUpIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { ChevronUpIcon }; +export { ChevronUpIcon } diff --git a/src/components/_shared/components/icons/cross-small-icon.tsx b/src/components/_shared/components/icons/cross-small-icon.tsx index 4b7e96b..3ddb1f6 100644 --- a/src/components/_shared/components/icons/cross-small-icon.tsx +++ b/src/components/_shared/components/icons/cross-small-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const CrossSmallIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const CrossSmallIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { CrossSmallIcon }; +export { CrossSmallIcon } diff --git a/src/components/_shared/components/icons/eye-none-icon.tsx b/src/components/_shared/components/icons/eye-none-icon.tsx index 24e927c..616c85e 100644 --- a/src/components/_shared/components/icons/eye-none-icon.tsx +++ b/src/components/_shared/components/icons/eye-none-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const EyeNoneIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const EyeNoneIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { EyeNoneIcon }; +export { EyeNoneIcon } diff --git a/src/components/_shared/components/icons/eye-open-icon.tsx b/src/components/_shared/components/icons/eye-open-icon.tsx index 52846cb..372dfcd 100644 --- a/src/components/_shared/components/icons/eye-open-icon.tsx +++ b/src/components/_shared/components/icons/eye-open-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const EyeOpenIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const EyeOpenIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { EyeOpenIcon }; +export { EyeOpenIcon } diff --git a/src/components/_shared/components/icons/magnifying-glass-icon.tsx b/src/components/_shared/components/icons/magnifying-glass-icon.tsx index ce76e46..3399767 100644 --- a/src/components/_shared/components/icons/magnifying-glass-icon.tsx +++ b/src/components/_shared/components/icons/magnifying-glass-icon.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -const MagnifyingGlassIcon = (props: React.ComponentPropsWithRef<"svg">) => { - return ( - - - - ); -}; +const MagnifyingGlassIcon = (props: React.ComponentPropsWithRef<'svg'>) => { + return ( + + + + ) +} -export { MagnifyingGlassIcon }; +export { MagnifyingGlassIcon } diff --git a/src/components/_shared/components/modal-close/modal-close.tsx b/src/components/_shared/components/modal-close/modal-close.tsx index 7d6e113..12f245c 100644 --- a/src/components/_shared/components/modal-close/modal-close.tsx +++ b/src/components/_shared/components/modal-close/modal-close.tsx @@ -1,20 +1,15 @@ -"use client"; +'use client' -import { DialogClose as DialogClosePrimitive } from "@radix-ui/react-dialog"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { DialogClose as DialogClosePrimitive } from '@radix-ui/react-dialog' +import { cn } from '@renderui/utils' +import React from 'react' -type DialogCloseProps = React.ComponentProps; +type DialogCloseProps = React.ComponentProps const ModalClose = (props: DialogCloseProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return +} -export { ModalClose }; +export { ModalClose } diff --git a/src/components/_shared/components/modal-description/modal-description.tsx b/src/components/_shared/components/modal-description/modal-description.tsx index 77986a0..e15d226 100644 --- a/src/components/_shared/components/modal-description/modal-description.tsx +++ b/src/components/_shared/components/modal-description/modal-description.tsx @@ -1,19 +1,19 @@ -import { cx } from "@renderui/utils"; -import React from "react"; +import { cx } from '@renderui/utils' +import React from 'react' -import { Text, TextProps } from "@/components/text"; +import { Text, TextProps } from '@/components/text' const ModalDescription = (props: TextProps) => { - const { className, size = "sm", ...restProps } = props; + const { className, size = 'sm', ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { ModalDescription }; +export { ModalDescription } diff --git a/src/components/_shared/components/modal-footer/modal-footer.tsx b/src/components/_shared/components/modal-footer/modal-footer.tsx index f01576a..9f168c3 100644 --- a/src/components/_shared/components/modal-footer/modal-footer.tsx +++ b/src/components/_shared/components/modal-footer/modal-footer.tsx @@ -1,21 +1,21 @@ -import { cx } from "@renderui/utils"; -import React from "react"; +import { cx } from '@renderui/utils' +import React from 'react' -import { Flex, FlexProps } from "@/components/flex"; +import { Flex, FlexProps } from '@/components/flex' const ModalFooter = (props: FlexProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { ModalFooter }; +export { ModalFooter } diff --git a/src/components/_shared/components/modal-header/modal-header.tsx b/src/components/_shared/components/modal-header/modal-header.tsx index f949dc2..97ac5b2 100644 --- a/src/components/_shared/components/modal-header/modal-header.tsx +++ b/src/components/_shared/components/modal-header/modal-header.tsx @@ -1,18 +1,18 @@ -import { cx } from "@renderui/utils"; -import React from "react"; +import { cx } from '@renderui/utils' +import React from 'react' -import { Grid, GridProps } from "@/components/grid"; +import { Grid, GridProps } from '@/components/grid' const ModalHeader = (props: GridProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { ModalHeader }; +export { ModalHeader } diff --git a/src/components/_shared/components/modal-title/modal-title.tsx b/src/components/_shared/components/modal-title/modal-title.tsx index af12c15..0cf8de2 100644 --- a/src/components/_shared/components/modal-title/modal-title.tsx +++ b/src/components/_shared/components/modal-title/modal-title.tsx @@ -4,17 +4,17 @@ import React, { ComponentProps } from 'react' import { DialogTitle } from '@radix-ui/react-dialog' const ModalTitle = (props: ComponentProps) => { - const { ref, className, color = 'mode-contrast', ...restProps } = props + const { ref, className, color = 'mode-contrast', ...restProps } = props - return ( - - ) + return ( + + ) } export { ModalTitle } diff --git a/src/components/_shared/hooks/use-aria-handlers.ts b/src/components/_shared/hooks/use-aria-handlers.ts index bcafea1..2e19bbf 100644 --- a/src/components/_shared/hooks/use-aria-handlers.ts +++ b/src/components/_shared/hooks/use-aria-handlers.ts @@ -1,17 +1,17 @@ import { mergeProps } from '@renderui/utils' import React from 'react' import { - FocusProps, - FocusRingProps, - HoverProps, - LongPressProps, - PressEvent, - PressHookProps, - useFocus, - useFocusRing, - useHover, - useLongPress, - usePress, + FocusProps, + FocusRingProps, + HoverProps, + LongPressProps, + PressEvent, + PressHookProps, + useFocus, + useFocusRing, + useHover, + useLongPress, + usePress, } from 'react-aria' import { UseAriaHandlersProps } from '@/components/_shared/types/aria' @@ -20,177 +20,177 @@ import { isKeyboardPointerType } from '@/components/_shared/utils/is-keyboard-po import { chain } from '@renderui/utils/chain' function useAriaHandlers( - props: OrUndefined, - ref: React.ForwardedRef | undefined, + props: OrUndefined, + ref: React.ForwardedRef | undefined, ) { - const { - // PRESS - isPressDisabled, - isPressed: isPressedControlled, - preventFocusOnPress, - allowTextSelectionOnPress, - shouldCancelOnPointerExit, - onPress, - onPressStart, - onPressEnd, - onPressChange, - onPressUp, - - // KEYBOARD PRESS - onKeyboardPressStart, - onKeyboardPressEnd, - onKeyboardPress, - - // LONG PRESS - isLongPressDisabled, - longPressTreshold, - longPressAccessibilityDescription, - onLongPressStart, - onLongPress, - onLongPressEnd, - - // FOCUS - isFocusDisabled, - onFocus, - onFocusChange, - onBlur, - - // FOCUS WITHIN - isTextInput, - isFocusWithin, - - // HOVER - isHoverDisabled, - onHoverStart, - onHoverChange, - onHoverEnd, - - // NATIVE - onDragStart, - onKeyDown, - onKeyUp, - onMouseDown, - onPointerDown, - onPointerEnter, - onPointerLeave, - onPointerUp, - - isUsingAriaPressProps = true, - } = props - - const [isKeyboardPressed, setIsKeyboardPressed] = React.useState(false) - const [isLongPressed, setIsLongPressed] = React.useState(false) - - const handlePressStart = (event: PressEvent) => { - if (isKeyboardPointerType(event)) setIsKeyboardPressed(true) - } - - const handlePressEnd = (event: PressEvent) => { - if (isKeyboardPointerType(event)) setIsKeyboardPressed(false) - } - - const handleKeyboardPressStart = (event: PressEvent) => { - if (isKeyboardPointerType(event) && onKeyboardPressStart) onKeyboardPressStart(event) - } - - const handleKeyboardPressEnd = (event: PressEvent) => { - if (isKeyboardPointerType(event) && onKeyboardPressEnd) onKeyboardPressEnd(event) - } - - const handleKeyboardPress = (event: PressEvent) => { - if (isKeyboardPointerType(event) && onKeyboardPress) onKeyboardPress(event) - } - - // hooks propeties are asserted due to the decision to keep exactOptionalPropertyTypes: true - TS rule - - const { pressProps, isPressed } = usePress({ - ref, - isPressed: isPressedControlled, - preventFocusOnPress, - allowTextSelectionOnPress, - shouldCancelOnPointerExit, - isDisabled: isPressDisabled, - onPressChange, - onPressUp, - onPress: chain(handleKeyboardPress, onPress), - onPressStart: chain(handlePressStart, handleKeyboardPressStart, onPressStart), - onPressEnd: chain(handlePressEnd, handleKeyboardPressEnd, onPressEnd), - } as PressHookProps) - - const { longPressProps } = useLongPress({ - isDisabled: isLongPressDisabled, - threshold: longPressTreshold, - accessibilityDescription: longPressAccessibilityDescription, - onLongPressStart: chain(onLongPressStart, () => setIsLongPressed(true)), - onLongPress, - onLongPressEnd, - } as LongPressProps) - - const { focusProps } = useFocus({ - isDisabled: isFocusDisabled, - onFocus, - onBlur, - onFocusChange, - } as FocusProps) - - const { - focusProps: focusVisibleProps, - isFocusVisible, - isFocused, - } = useFocusRing({ - isTextInput, - within: isFocusWithin, - } as FocusRingProps) - - const { hoverProps, isHovered } = useHover({ - isDisabled: isHoverDisabled, - onHoverStart, - onHoverChange, - onHoverEnd, - } as HoverProps) - - const ariaHandlerProps = mergeProps( - isLongPressDisabled ? undefined : longPressProps, - isUsingAriaPressProps ? pressProps : undefined, - focusProps, - focusVisibleProps, - hoverProps, - { - onPointerUp: chain(onPointerUp, () => setIsLongPressed(false)), - onPointerLeave: chain(onPointerLeave, () => setIsLongPressed(false)), - onDragStart, - onKeyDown, - onKeyUp, - onMouseDown, - onPointerDown, - onPointerEnter, - }, - ) - - const accessibilityProps = { - 'aria-pressed': isPressed, - 'data-pressed': isPressed, - 'data-long-pressed': isLongPressed, - 'data-keyboard-pressed': isKeyboardPressed, - 'data-hover': isHovered, - 'data-focus-within': isFocusWithin ? isFocused : undefined, - 'data-focus': isFocusWithin ? undefined : isFocused, - 'data-focus-visible': isFocusVisible, - } - - return { - ariaComponentProps: { - ...accessibilityProps, - ...ariaHandlerProps, - }, - ariaFlags: { - isPressed, - isKeyboardPressed, - isFocused, - isFocusVisible, - isHovered, - }, - } + const { + // PRESS + isPressDisabled, + isPressed: isPressedControlled, + preventFocusOnPress, + allowTextSelectionOnPress, + shouldCancelOnPointerExit, + onPress, + onPressStart, + onPressEnd, + onPressChange, + onPressUp, + + // KEYBOARD PRESS + onKeyboardPressStart, + onKeyboardPressEnd, + onKeyboardPress, + + // LONG PRESS + isLongPressDisabled, + longPressTreshold, + longPressAccessibilityDescription, + onLongPressStart, + onLongPress, + onLongPressEnd, + + // FOCUS + isFocusDisabled, + onFocus, + onFocusChange, + onBlur, + + // FOCUS WITHIN + isTextInput, + isFocusWithin, + + // HOVER + isHoverDisabled, + onHoverStart, + onHoverChange, + onHoverEnd, + + // NATIVE + onDragStart, + onKeyDown, + onKeyUp, + onMouseDown, + onPointerDown, + onPointerEnter, + onPointerLeave, + onPointerUp, + + isUsingAriaPressProps = true, + } = props + + const [isKeyboardPressed, setIsKeyboardPressed] = React.useState(false) + const [isLongPressed, setIsLongPressed] = React.useState(false) + + const handlePressStart = (event: PressEvent) => { + if (isKeyboardPointerType(event)) setIsKeyboardPressed(true) + } + + const handlePressEnd = (event: PressEvent) => { + if (isKeyboardPointerType(event)) setIsKeyboardPressed(false) + } + + const handleKeyboardPressStart = (event: PressEvent) => { + if (isKeyboardPointerType(event) && onKeyboardPressStart) onKeyboardPressStart(event) + } + + const handleKeyboardPressEnd = (event: PressEvent) => { + if (isKeyboardPointerType(event) && onKeyboardPressEnd) onKeyboardPressEnd(event) + } + + const handleKeyboardPress = (event: PressEvent) => { + if (isKeyboardPointerType(event) && onKeyboardPress) onKeyboardPress(event) + } + + // hooks propeties are asserted due to the decision to keep exactOptionalPropertyTypes: true - TS rule + + const { pressProps, isPressed } = usePress({ + ref, + isPressed: isPressedControlled, + preventFocusOnPress, + allowTextSelectionOnPress, + shouldCancelOnPointerExit, + isDisabled: isPressDisabled, + onPressChange, + onPressUp, + onPress: chain(handleKeyboardPress, onPress), + onPressStart: chain(handlePressStart, handleKeyboardPressStart, onPressStart), + onPressEnd: chain(handlePressEnd, handleKeyboardPressEnd, onPressEnd), + } as PressHookProps) + + const { longPressProps } = useLongPress({ + isDisabled: isLongPressDisabled, + threshold: longPressTreshold, + accessibilityDescription: longPressAccessibilityDescription, + onLongPressStart: chain(onLongPressStart, () => setIsLongPressed(true)), + onLongPress, + onLongPressEnd, + } as LongPressProps) + + const { focusProps } = useFocus({ + isDisabled: isFocusDisabled, + onFocus, + onBlur, + onFocusChange, + } as FocusProps) + + const { + focusProps: focusVisibleProps, + isFocusVisible, + isFocused, + } = useFocusRing({ + isTextInput, + within: isFocusWithin, + } as FocusRingProps) + + const { hoverProps, isHovered } = useHover({ + isDisabled: isHoverDisabled, + onHoverStart, + onHoverChange, + onHoverEnd, + } as HoverProps) + + const ariaHandlerProps = mergeProps( + isLongPressDisabled ? undefined : longPressProps, + isUsingAriaPressProps ? pressProps : undefined, + focusProps, + focusVisibleProps, + hoverProps, + { + onPointerUp: chain(onPointerUp, () => setIsLongPressed(false)), + onPointerLeave: chain(onPointerLeave, () => setIsLongPressed(false)), + onDragStart, + onKeyDown, + onKeyUp, + onMouseDown, + onPointerDown, + onPointerEnter, + }, + ) + + const accessibilityProps = { + 'aria-pressed': isPressed, + 'data-pressed': isPressed, + 'data-long-pressed': isLongPressed, + 'data-keyboard-pressed': isKeyboardPressed, + 'data-hover': isHovered, + 'data-focus-within': isFocusWithin ? isFocused : undefined, + 'data-focus': isFocusWithin ? undefined : isFocused, + 'data-focus-visible': isFocusVisible, + } + + return { + ariaComponentProps: { + ...accessibilityProps, + ...ariaHandlerProps, + }, + ariaFlags: { + isPressed, + isKeyboardPressed, + isFocused, + isFocusVisible, + isHovered, + }, + } } export { useAriaHandlers } diff --git a/src/components/_shared/hooks/use-controllable-state.ts b/src/components/_shared/hooks/use-controllable-state.ts index e7e4eaa..86897bf 100644 --- a/src/components/_shared/hooks/use-controllable-state.ts +++ b/src/components/_shared/hooks/use-controllable-state.ts @@ -2,8 +2,8 @@ import { useFreshRef } from '@/components/_shared/hooks/use-fresh-ref' import { - UseControllableStateProps, - useUncontrolledState, + UseControllableStateProps, + useUncontrolledState, } from '@/components/_shared/hooks/use-uncontrolled-state' import { isFunction } from '@renderui/utils/is-function' import { noop } from '@renderui/utils/noop' @@ -12,32 +12,32 @@ import React from 'react' type SetStateFunction = (previousState?: T) => T function useControllableState({ - prop, - defaultProp, - onChange = noop, + prop, + defaultProp, + onChange = noop, }: UseControllableStateProps) { - const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange }) - const isControlled = prop !== undefined - const value = isControlled ? prop : uncontrolledProp - const handleChange = useFreshRef(onChange) + const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({ defaultProp, onChange }) + const isControlled = prop !== undefined + const value = isControlled ? prop : uncontrolledProp + const handleChange = useFreshRef(onChange) - const setValue: React.Dispatch> = React.useCallback( - (nextValue) => { - if (isControlled) { - const setter = nextValue as SetStateFunction - const value = typeof nextValue === 'function' ? setter(prop) : nextValue + const setValue: React.Dispatch> = React.useCallback( + (nextValue) => { + if (isControlled) { + const setter = nextValue as SetStateFunction + const value = typeof nextValue === 'function' ? setter(prop) : nextValue - if (value !== prop) handleChange.current(value as T) + if (value !== prop) handleChange.current(value as T) - return - } + return + } - if (isFunction(setUncontrolledProp)) setUncontrolledProp(nextValue) - }, - [isControlled, prop, setUncontrolledProp, handleChange], - ) + if (isFunction(setUncontrolledProp)) setUncontrolledProp(nextValue) + }, + [isControlled, prop, setUncontrolledProp, handleChange], + ) - return [value, setValue] as [T, React.Dispatch>] + return [value, setValue] as [T, React.Dispatch>] } export { useControllableState } diff --git a/src/components/_shared/hooks/use-event-listener.ts b/src/components/_shared/hooks/use-event-listener.ts index 6e2b0ac..e4568ab 100644 --- a/src/components/_shared/hooks/use-event-listener.ts +++ b/src/components/_shared/hooks/use-event-listener.ts @@ -6,82 +6,82 @@ import React from 'react' /* MediaQueryList Event based useEventListener interface */ function useEventListener(props: { - event: K - handler: (event: MediaQueryListEventMap[K]) => void - element: MediaQueryList - enabled?: boolean - options?: boolean | AddEventListenerOptions + event: K + handler: (event: MediaQueryListEventMap[K]) => void + element: MediaQueryList + enabled?: boolean + options?: boolean | AddEventListenerOptions }): void /* Window Event based useEventListener interface */ function useEventListener(props: { - event: K - handler: (event: WindowEventMap[K]) => void - element?: undefined - enabled?: boolean - options?: boolean | AddEventListenerOptions + event: K + handler: (event: WindowEventMap[K]) => void + element?: undefined + enabled?: boolean + options?: boolean | AddEventListenerOptions }): void /* Element Event based useEventListener interface */ function useEventListener< - K extends keyof HTMLElementEventMap, - T extends HTMLElement = HTMLDivElement, + K extends keyof HTMLElementEventMap, + T extends HTMLElement = HTMLDivElement, >(props: { - event: K - handler: (event: HTMLElementEventMap[K]) => void - element: T | null - enabled?: boolean - options?: boolean | AddEventListenerOptions + event: K + handler: (event: HTMLElementEventMap[K]) => void + element: T | null + enabled?: boolean + options?: boolean | AddEventListenerOptions }): void /* Document Event based useEventListener interface */ function useEventListener(props: { - event: K - handler: (event: DocumentEventMap[K]) => void - element: Document - enabled?: boolean - options?: boolean | AddEventListenerOptions + event: K + handler: (event: DocumentEventMap[K]) => void + element: Document + enabled?: boolean + options?: boolean | AddEventListenerOptions }): void function useEventListener< - KW extends keyof WindowEventMap, - KH extends keyof HTMLElementEventMap, - KM extends keyof MediaQueryListEventMap, - T extends HTMLElement | MediaQueryList | void = void, + KW extends keyof WindowEventMap, + KH extends keyof HTMLElementEventMap, + KM extends keyof MediaQueryListEventMap, + T extends HTMLElement | MediaQueryList | void = void, >(props: { - event: KW | KH | KM - element?: T - options?: boolean | AddEventListenerOptions - enabled?: boolean - handler: ( - event: WindowEventMap[KW] | HTMLElementEventMap[KH] | MediaQueryListEventMap[KM] | Event, - ) => void + event: KW | KH | KM + element?: T + options?: boolean | AddEventListenerOptions + enabled?: boolean + handler: ( + event: WindowEventMap[KW] | HTMLElementEventMap[KH] | MediaQueryListEventMap[KM] | Event, + ) => void }) { - const { event, element, options, handler, enabled = true } = props + const { event, element, options, handler, enabled = true } = props - /* Create a ref that stores handler */ - const freshHandler = useFreshRef(handler) - const freshOptions = useFreshRef(options) + /* Create a ref that stores handler */ + const freshHandler = useFreshRef(handler) + const freshOptions = useFreshRef(options) - React.useEffect(() => { - if (!enabled) return noop + React.useEffect(() => { + if (!enabled) return noop - /* Define the listening target */ - const targetElement: T | HTMLElement | null = - element ?? (typeof window !== 'undefined' ? window.document.documentElement : null) + /* Define the listening target */ + const targetElement: T | HTMLElement | null = + element ?? (typeof window !== 'undefined' ? window.document.documentElement : null) - if (!(targetElement && targetElement.addEventListener)) return noop + if (!(targetElement && targetElement.addEventListener)) return noop - /* Create event listener that calls handler function stored in ref */ - const listener: typeof handler = (event) => freshHandler.current(event) + /* Create event listener that calls handler function stored in ref */ + const listener: typeof handler = (event) => freshHandler.current(event) - targetElement.addEventListener(event, listener, freshOptions.current) + targetElement.addEventListener(event, listener, freshOptions.current) - /* Remove event listener on cleanup */ - return () => { - targetElement.removeEventListener(event, listener, freshOptions.current) - } - }, [event, element, enabled]) + /* Remove event listener on cleanup */ + return () => { + targetElement.removeEventListener(event, listener, freshOptions.current) + } + }, [event, element, enabled]) } export { useEventListener } diff --git a/src/components/_shared/hooks/use-fresh-ref.ts b/src/components/_shared/hooks/use-fresh-ref.ts index ac886bb..c850c1a 100644 --- a/src/components/_shared/hooks/use-fresh-ref.ts +++ b/src/components/_shared/hooks/use-fresh-ref.ts @@ -3,13 +3,13 @@ import React from 'react' function useFreshRef(value: T) { - const ref = React.useRef(value) + const ref = React.useRef(value) - React.useEffect(() => { - ref.current = value - }, [value]) + React.useEffect(() => { + ref.current = value + }, [value]) - return ref + return ref } export { useFreshRef } diff --git a/src/components/_shared/hooks/use-keyboard-hotkey.ts b/src/components/_shared/hooks/use-keyboard-hotkey.ts index 5a5c536..a9c2c4b 100644 --- a/src/components/_shared/hooks/use-keyboard-hotkey.ts +++ b/src/components/_shared/hooks/use-keyboard-hotkey.ts @@ -6,67 +6,67 @@ import { HotkeyCallback, useHotkeys } from 'react-hotkeys-hook' import { HotkeysEvent, OptionsOrDependencyArray } from 'react-hotkeys-hook/dist/types' const DEFAULT_KEY_COMBINATION_OPTIONS: OptionsOrDependencyArray = { - preventDefault: true, + preventDefault: true, } type UseKeyboardHotkeyArgs = { - keyCombination?: string | string[] - keyCombinationOptions?: OptionsOrDependencyArray - isKeyCombinationCasingIgnored?: boolean - onKeyCombinationMatch?: HotkeyCallback + keyCombination?: string | string[] + keyCombinationOptions?: OptionsOrDependencyArray + isKeyCombinationCasingIgnored?: boolean + onKeyCombinationMatch?: HotkeyCallback } function useKeyboardHotkey(props: UseKeyboardHotkeyArgs) { - const { - onKeyCombinationMatch, - keyCombination, - keyCombinationOptions, - isKeyCombinationCasingIgnored = true, - } = props + const { + onKeyCombinationMatch, + keyCombination, + keyCombinationOptions, + isKeyCombinationCasingIgnored = true, + } = props - const freshOnMatch = useFreshRef(onKeyCombinationMatch) + const freshOnMatch = useFreshRef(onKeyCombinationMatch) - const freshKeyCombination = useFreshRef(keyCombination) + const freshKeyCombination = useFreshRef(keyCombination) - const memoizedKeyCombination = React.useMemo(() => { - return ( - (Array.isArray(freshKeyCombination.current) - ? freshKeyCombination.current.join('+') - : freshKeyCombination.current) ?? [] - ) - }, []) + const memoizedKeyCombination = React.useMemo(() => { + return ( + (Array.isArray(freshKeyCombination.current) + ? freshKeyCombination.current.join('+') + : freshKeyCombination.current) ?? [] + ) + }, []) - const freshOptions = useFreshRef(keyCombinationOptions) + const freshOptions = useFreshRef(keyCombinationOptions) - const memoizedOptions = React.useMemo(() => { - return freshOptions.current - ? { ...DEFAULT_KEY_COMBINATION_OPTIONS, ...freshOptions.current } - : DEFAULT_KEY_COMBINATION_OPTIONS - }, []) + const memoizedOptions = React.useMemo(() => { + return freshOptions.current + ? { ...DEFAULT_KEY_COMBINATION_OPTIONS, ...freshOptions.current } + : DEFAULT_KEY_COMBINATION_OPTIONS + }, []) - const hasCasingTestFailed = React.useCallback( - (eventKey: string, optionKeys: readonly string[] | undefined) => { - if (isKeyCombinationCasingIgnored) return false + const hasCasingTestFailed = React.useCallback( + (eventKey: string, optionKeys: readonly string[] | undefined) => { + if (isKeyCombinationCasingIgnored) return false - const passesCasingTest = optionKeys?.includes(eventKey) + const passesCasingTest = optionKeys?.includes(eventKey) - return !passesCasingTest - }, - [], - ) + return !passesCasingTest + }, + [], + ) - const handleKeyCombinationDown = React.useCallback( - (event: KeyboardEvent, options: HotkeysEvent) => { - if (!freshOnMatch.current) return + const handleKeyCombinationDown = React.useCallback( + (event: KeyboardEvent, options: HotkeysEvent) => { + if (!freshOnMatch.current) return - if (hasCasingTestFailed(event.key, options?.keys)) return + if (hasCasingTestFailed(event.key, options?.keys)) return - freshOnMatch.current(event, options) - }, - [hasCasingTestFailed], - ) + freshOnMatch.current(event, options) + }, + [hasCasingTestFailed], + ) - useHotkeys(memoizedKeyCombination, handleKeyCombinationDown, memoizedOptions) + useHotkeys(memoizedKeyCombination, handleKeyCombinationDown, memoizedOptions) } export { useKeyboardHotkey } diff --git a/src/components/_shared/hooks/use-merged-ref.ts b/src/components/_shared/hooks/use-merged-ref.ts index 8d4c5a2..4e0e302 100644 --- a/src/components/_shared/hooks/use-merged-ref.ts +++ b/src/components/_shared/hooks/use-merged-ref.ts @@ -1,44 +1,38 @@ -"use client"; +'use client' -import { isFunction } from "@renderui/utils/is-function"; -import React from "react"; +import { isFunction } from '@renderui/utils/is-function' +import React from 'react' -function handleRef( - element: T | null, - ref: React.Ref | undefined | null -) { - if (!element || !ref) return; - - if (isFunction(ref)) { - ref(element); +function handleRef(element: T | null, ref: React.Ref | undefined | null) { + if (!element || !ref) return - return; - } + if (isFunction(ref)) { + ref(element) - // eslint-disable-next-line padding-line-between-statements, no-param-reassign - (ref as React.RefObject).current = element; + return + } + // eslint-disable-next-line padding-line-between-statements, no-param-reassign + ;(ref as React.RefObject).current = element } function mergeRefs( - element: T | null, - refs: Array | undefined | null> + element: T | null, + refs: Array | undefined | null>, ) { - if (!refs) return; + if (!refs) return - refs.filter(Boolean).forEach((ref) => { - handleRef(element, ref); - }); + refs.filter(Boolean).forEach((ref) => { + handleRef(element, ref) + }) } -function useMergedRef( - refs: Array | undefined | null> -) { - return React.useCallback( - (element: T) => { - mergeRefs(element, refs); - }, - [refs] - ); +function useMergedRef(refs: Array | undefined | null>) { + return React.useCallback( + (element: T) => { + mergeRefs(element, refs) + }, + [refs], + ) } -export { useMergedRef }; +export { useMergedRef } diff --git a/src/components/_shared/hooks/use-mutation-observer.ts b/src/components/_shared/hooks/use-mutation-observer.ts index ade2b8c..34916f3 100644 --- a/src/components/_shared/hooks/use-mutation-observer.ts +++ b/src/components/_shared/hooks/use-mutation-observer.ts @@ -4,24 +4,24 @@ import React from 'react' import { useFreshRef } from '@/components/_shared/hooks/use-fresh-ref' function useMutationObserver( - node: T | null, - callback: MutationCallback, - options: MutationObserverInit, + node: T | null, + callback: MutationCallback, + options: MutationObserverInit, ) { - const freshCallback = useFreshRef(callback) - const freshOptions = useFreshRef(options) + const freshCallback = useFreshRef(callback) + const freshOptions = useFreshRef(options) - React.useEffect(() => { - if (!node) return undefined + React.useEffect(() => { + if (!node) return undefined - const observer = new MutationObserver(freshCallback.current) + const observer = new MutationObserver(freshCallback.current) - observer.observe(node, freshOptions.current) + observer.observe(node, freshOptions.current) - return () => { - observer.disconnect() - } - }, [node]) + return () => { + observer.disconnect() + } + }, [node]) } export { useMutationObserver } diff --git a/src/components/_shared/hooks/use-on-click-outside.ts b/src/components/_shared/hooks/use-on-click-outside.ts index d33eb23..75170f8 100644 --- a/src/components/_shared/hooks/use-on-click-outside.ts +++ b/src/components/_shared/hooks/use-on-click-outside.ts @@ -5,43 +5,43 @@ import { useEventListener } from '@/components/_shared/hooks/use-event-listener' const DEFAULT_EXCEPTION_SELECTORS: string[] = [] type UseOnClickOutsideProps = { - element: T | null - exceptionSelectors?: string[] + element: T | null + exceptionSelectors?: string[] } & ( - | { - event: 'mousedown' | 'mouseup' - handler: ((event: MouseEvent) => void) | undefined - } - | { - event: 'pointerdown' | 'pointerup' - handler: ((event: PointerEvent) => void) | undefined - } + | { + event: 'mousedown' | 'mouseup' + handler: ((event: MouseEvent) => void) | undefined + } + | { + event: 'pointerdown' | 'pointerup' + handler: ((event: PointerEvent) => void) | undefined + } ) function useOnClickOutside(props: UseOnClickOutsideProps) { - const { event, element, handler, exceptionSelectors = DEFAULT_EXCEPTION_SELECTORS } = props - - useEventListener({ - event, - element: element, - handler: (event) => { - if (!(event.target instanceof Node)) { - return - } - - if (!handler || element?.contains(event.target)) { - return - } - - for (const selector of exceptionSelectors) { - if ((event.target as Element).matches(selector)) { - return - } - } - - handler(event as PointerEvent) - }, - }) + const { event, element, handler, exceptionSelectors = DEFAULT_EXCEPTION_SELECTORS } = props + + useEventListener({ + event, + element: element, + handler: (event) => { + if (!(event.target instanceof Node)) { + return + } + + if (!handler || element?.contains(event.target)) { + return + } + + for (const selector of exceptionSelectors) { + if ((event.target as Element).matches(selector)) { + return + } + } + + handler(event as PointerEvent) + }, + }) } export { useOnClickOutside } diff --git a/src/components/_shared/hooks/use-uncontrolled-state.ts b/src/components/_shared/hooks/use-uncontrolled-state.ts index 2dba5c2..f53d0f4 100644 --- a/src/components/_shared/hooks/use-uncontrolled-state.ts +++ b/src/components/_shared/hooks/use-uncontrolled-state.ts @@ -5,27 +5,27 @@ import React from 'react' import { useFreshRef } from '@/components/_shared/hooks/use-fresh-ref' type UseControllableStateProps = { - prop?: T | undefined - defaultProp?: T | undefined - onChange: ((state: T) => void) | undefined + prop?: T | undefined + defaultProp?: T | undefined + onChange: ((state: T) => void) | undefined } function useUncontrolledState({ - defaultProp, - onChange, + defaultProp, + onChange, }: Omit, 'prop'>) { - const [value, setValue] = React.useState(defaultProp) - const previousValueRef = React.useRef(value) - const handleChange = useFreshRef(onChange) - - React.useEffect(() => { - if (previousValueRef.current !== value) { - handleChange.current?.(value as T) - previousValueRef.current = value - } - }, [value, previousValueRef, handleChange]) - - return [value, setValue] + const [value, setValue] = React.useState(defaultProp) + const previousValueRef = React.useRef(value) + const handleChange = useFreshRef(onChange) + + React.useEffect(() => { + if (previousValueRef.current !== value) { + handleChange.current?.(value as T) + previousValueRef.current = value + } + }, [value, previousValueRef, handleChange]) + + return [value, setValue] } export { useUncontrolledState } diff --git a/src/components/_shared/types/aria.ts b/src/components/_shared/types/aria.ts index 50a53d1..dfb534b 100644 --- a/src/components/_shared/types/aria.ts +++ b/src/components/_shared/types/aria.ts @@ -1,51 +1,51 @@ import { - AriaFocusRingProps, - FocusProps, - HoverProps, - LongPressProps, - PressEvent, - PressProps, + AriaFocusRingProps, + FocusProps, + HoverProps, + LongPressProps, + PressEvent, + PressProps, } from 'react-aria' type UseAriaHandlersProps = { - isPressDisabled: PressProps['isDisabled'] | undefined - isPressed: PressProps['isPressed'] | undefined - preventFocusOnPress: PressProps['preventFocusOnPress'] | undefined - allowTextSelectionOnPress: PressProps['allowTextSelectionOnPress'] | undefined - shouldCancelOnPointerExit: PressProps['shouldCancelOnPointerExit'] | undefined - onPress: PressProps['onPress'] | undefined - onPressStart: PressProps['onPressStart'] | undefined - onPressEnd: PressProps['onPressEnd'] | undefined - onPressChange: PressProps['onPressChange'] | undefined - onPressUp: PressProps['onPressUp'] | undefined - onKeyboardPress: ((event: PressEvent) => void) | undefined - onKeyboardPressStart: ((event: PressEvent) => void) | undefined - onKeyboardPressEnd: ((event: PressEvent) => void) | undefined - isLongPressDisabled: LongPressProps['isDisabled'] | undefined - longPressTreshold: LongPressProps['threshold'] | undefined - longPressAccessibilityDescription: LongPressProps['accessibilityDescription'] | undefined - onLongPressStart: LongPressProps['onLongPressStart'] | undefined - onLongPress: LongPressProps['onLongPress'] | undefined - onLongPressEnd: LongPressProps['onLongPressEnd'] | undefined - isFocusDisabled: FocusProps['isDisabled'] | undefined - onFocus: FocusProps['onFocus'] | undefined - onFocusChange: FocusProps['onFocusChange'] | undefined - onBlur: FocusProps['onBlur'] | undefined - isTextInput: AriaFocusRingProps['isTextInput'] | undefined - isFocusWithin: AriaFocusRingProps['within'] | undefined - isHoverDisabled: HoverProps['isDisabled'] | undefined - onHoverStart: HoverProps['onHoverStart'] | undefined - onHoverChange: HoverProps['onHoverChange'] | undefined - onHoverEnd: HoverProps['onHoverEnd'] | undefined - isUsingAriaPressProps?: boolean - onDragStart: React.DragEventHandler | undefined - onKeyDown: React.KeyboardEventHandler | undefined - onKeyUp: React.KeyboardEventHandler | undefined - onMouseDown: React.MouseEventHandler | undefined - onPointerDown: React.PointerEventHandler | undefined - onPointerEnter: React.PointerEventHandler | undefined - onPointerLeave: React.PointerEventHandler | undefined - onPointerUp: React.PointerEventHandler | undefined + isPressDisabled: PressProps['isDisabled'] | undefined + isPressed: PressProps['isPressed'] | undefined + preventFocusOnPress: PressProps['preventFocusOnPress'] | undefined + allowTextSelectionOnPress: PressProps['allowTextSelectionOnPress'] | undefined + shouldCancelOnPointerExit: PressProps['shouldCancelOnPointerExit'] | undefined + onPress: PressProps['onPress'] | undefined + onPressStart: PressProps['onPressStart'] | undefined + onPressEnd: PressProps['onPressEnd'] | undefined + onPressChange: PressProps['onPressChange'] | undefined + onPressUp: PressProps['onPressUp'] | undefined + onKeyboardPress: ((event: PressEvent) => void) | undefined + onKeyboardPressStart: ((event: PressEvent) => void) | undefined + onKeyboardPressEnd: ((event: PressEvent) => void) | undefined + isLongPressDisabled: LongPressProps['isDisabled'] | undefined + longPressTreshold: LongPressProps['threshold'] | undefined + longPressAccessibilityDescription: LongPressProps['accessibilityDescription'] | undefined + onLongPressStart: LongPressProps['onLongPressStart'] | undefined + onLongPress: LongPressProps['onLongPress'] | undefined + onLongPressEnd: LongPressProps['onLongPressEnd'] | undefined + isFocusDisabled: FocusProps['isDisabled'] | undefined + onFocus: FocusProps['onFocus'] | undefined + onFocusChange: FocusProps['onFocusChange'] | undefined + onBlur: FocusProps['onBlur'] | undefined + isTextInput: AriaFocusRingProps['isTextInput'] | undefined + isFocusWithin: AriaFocusRingProps['within'] | undefined + isHoverDisabled: HoverProps['isDisabled'] | undefined + onHoverStart: HoverProps['onHoverStart'] | undefined + onHoverChange: HoverProps['onHoverChange'] | undefined + onHoverEnd: HoverProps['onHoverEnd'] | undefined + isUsingAriaPressProps?: boolean + onDragStart: React.DragEventHandler | undefined + onKeyDown: React.KeyboardEventHandler | undefined + onKeyUp: React.KeyboardEventHandler | undefined + onMouseDown: React.MouseEventHandler | undefined + onPointerDown: React.PointerEventHandler | undefined + onPointerEnter: React.PointerEventHandler | undefined + onPointerLeave: React.PointerEventHandler | undefined + onPointerUp: React.PointerEventHandler | undefined } type OptionalAriaProps = Partial diff --git a/src/components/_shared/types/as-child.ts b/src/components/_shared/types/as-child.ts index 9e7d227..c79c456 100644 --- a/src/components/_shared/types/as-child.ts +++ b/src/components/_shared/types/as-child.ts @@ -1,5 +1,5 @@ type AsChildProp = { - asChild?: boolean + asChild?: boolean } export type { AsChildProp } diff --git a/src/components/_shared/types/colors.ts b/src/components/_shared/types/colors.ts index 9c22fec..8816de2 100644 --- a/src/components/_shared/types/colors.ts +++ b/src/components/_shared/types/colors.ts @@ -1,13 +1,13 @@ type Color = - | 'mode' - | 'mode-accent' - | 'mode-contrast' - | 'mode-contrast-accent' - | 'primary' - | 'secondary' - | 'destructive' - | 'success' - | 'warning' - | 'info' + | 'mode' + | 'mode-accent' + | 'mode-contrast' + | 'mode-contrast-accent' + | 'primary' + | 'secondary' + | 'destructive' + | 'success' + | 'warning' + | 'info' export type { Color } diff --git a/src/components/_shared/types/or-undefined.ts b/src/components/_shared/types/or-undefined.ts index 6264483..df209f1 100644 --- a/src/components/_shared/types/or-undefined.ts +++ b/src/components/_shared/types/or-undefined.ts @@ -5,7 +5,7 @@ * @template T - The original type to be transformed. */ type OrUndefined = { - [K in keyof T]: T[K] | undefined + [K in keyof T]: T[K] | undefined } export type { OrUndefined } diff --git a/src/components/_shared/types/prettify.ts b/src/components/_shared/types/prettify.ts index 1ad3946..bdef97b 100644 --- a/src/components/_shared/types/prettify.ts +++ b/src/components/_shared/types/prettify.ts @@ -6,8 +6,8 @@ * @template T - The original type to be transformed. */ type Prettify = { - [K in keyof T]: T[K] - // eslint-disable-next-line functional/readonly-type + [K in keyof T]: T[K] + // eslint-disable-next-line functional/readonly-type } & {} export type { Prettify } diff --git a/src/components/_shared/types/variants.ts b/src/components/_shared/types/variants.ts index 867409b..fbfdca2 100644 --- a/src/components/_shared/types/variants.ts +++ b/src/components/_shared/types/variants.ts @@ -1,7 +1,7 @@ import { VariantProps } from '@renderui/utils' type NonNullableVariantProps any> = { - [K in keyof VariantProps]: NonNullable[K]> + [K in keyof VariantProps]: NonNullable[K]> } export type { NonNullableVariantProps } diff --git a/src/components/_shared/utils/focus-input.ts b/src/components/_shared/utils/focus-input.ts index 819cb3a..5fbd44e 100644 --- a/src/components/_shared/utils/focus-input.ts +++ b/src/components/_shared/utils/focus-input.ts @@ -3,15 +3,15 @@ import React from 'react' function focusInput(inputRef: React.RefObject) { - if (!inputRef?.current) return + if (!inputRef?.current) return - const { current: input } = inputRef + const { current: input } = inputRef - input.focus() + input.focus() - const valueLength = input.value.length + const valueLength = input.value.length - input.setSelectionRange(valueLength, valueLength) + input.setSelectionRange(valueLength, valueLength) } export { focusInput } diff --git a/src/components/_shared/utils/is-keyboard-pointer-type.ts b/src/components/_shared/utils/is-keyboard-pointer-type.ts index b0ecd31..4324259 100644 --- a/src/components/_shared/utils/is-keyboard-pointer-type.ts +++ b/src/components/_shared/utils/is-keyboard-pointer-type.ts @@ -3,7 +3,7 @@ import { PressEvent } from 'react-aria' function isKeyboardPointerType(event: PressEvent) { - return event.pointerType === 'keyboard' + return event.pointerType === 'keyboard' } export { isKeyboardPointerType } diff --git a/src/components/_shared/utils/split-aria-props.ts b/src/components/_shared/utils/split-aria-props.ts index f64a676..cc506b4 100644 --- a/src/components/_shared/utils/split-aria-props.ts +++ b/src/components/_shared/utils/split-aria-props.ts @@ -5,91 +5,91 @@ import { UseAriaHandlersProps } from '@/components/_shared/types/aria' type AriaHandlerPropsSelectorProps = T & Partial const splitAriaProps = (props: AriaHandlerPropsSelectorProps) => { - const { - isPressDisabled, - isPressed, - preventFocusOnPress, - allowTextSelectionOnPress, - shouldCancelOnPointerExit, - onPress, - onPressStart, - onPressEnd, - onPressChange, - onPressUp, - onKeyboardPress, - onKeyboardPressStart, - onKeyboardPressEnd, - isLongPressDisabled = true, - longPressTreshold, - longPressAccessibilityDescription, - onLongPressStart, - onLongPress, - onLongPressEnd, - isFocusDisabled, - onFocus, - onFocusChange, - onBlur, - isTextInput, - isFocusWithin, - isHoverDisabled, - onHoverStart, - onHoverChange, - onHoverEnd, - onDragStart, - onKeyDown, - onKeyUp, - onMouseDown, - onPointerDown, - onPointerEnter, - onPointerLeave, - onPointerUp, - ...nonAriaProps - } = props + const { + isPressDisabled, + isPressed, + preventFocusOnPress, + allowTextSelectionOnPress, + shouldCancelOnPointerExit, + onPress, + onPressStart, + onPressEnd, + onPressChange, + onPressUp, + onKeyboardPress, + onKeyboardPressStart, + onKeyboardPressEnd, + isLongPressDisabled = true, + longPressTreshold, + longPressAccessibilityDescription, + onLongPressStart, + onLongPress, + onLongPressEnd, + isFocusDisabled, + onFocus, + onFocusChange, + onBlur, + isTextInput, + isFocusWithin, + isHoverDisabled, + onHoverStart, + onHoverChange, + onHoverEnd, + onDragStart, + onKeyDown, + onKeyUp, + onMouseDown, + onPointerDown, + onPointerEnter, + onPointerLeave, + onPointerUp, + ...nonAriaProps + } = props - const ariaProps = { - isPressDisabled, - isPressed, - preventFocusOnPress, - allowTextSelectionOnPress, - shouldCancelOnPointerExit, - onPress, - onPressStart, - onPressEnd, - onPressChange, - onPressUp, - onKeyboardPress, - onKeyboardPressStart, - onKeyboardPressEnd, - isLongPressDisabled, - longPressTreshold, - longPressAccessibilityDescription, - onLongPressStart, - onLongPress, - onLongPressEnd, - isFocusDisabled, - onFocus, - onFocusChange, - onBlur, - isTextInput, - isFocusWithin, - isHoverDisabled, - onHoverStart, - onHoverChange, - onHoverEnd, - onDragStart, - onKeyDown, - onKeyUp, - onMouseDown, - onPointerDown, - onPointerEnter, - onPointerLeave, - onPointerUp, - } + const ariaProps = { + isPressDisabled, + isPressed, + preventFocusOnPress, + allowTextSelectionOnPress, + shouldCancelOnPointerExit, + onPress, + onPressStart, + onPressEnd, + onPressChange, + onPressUp, + onKeyboardPress, + onKeyboardPressStart, + onKeyboardPressEnd, + isLongPressDisabled, + longPressTreshold, + longPressAccessibilityDescription, + onLongPressStart, + onLongPress, + onLongPressEnd, + isFocusDisabled, + onFocus, + onFocusChange, + onBlur, + isTextInput, + isFocusWithin, + isHoverDisabled, + onHoverStart, + onHoverChange, + onHoverEnd, + onDragStart, + onKeyDown, + onKeyUp, + onMouseDown, + onPointerDown, + onPointerEnter, + onPointerLeave, + onPointerUp, + } - return { - ariaProps, - nonAriaProps, - } + return { + ariaProps, + nonAriaProps, + } } export { splitAriaProps } diff --git a/src/components/_shared/variants/letter-spacing.ts b/src/components/_shared/variants/letter-spacing.ts index 3d1422e..bec6dff 100644 --- a/src/components/_shared/variants/letter-spacing.ts +++ b/src/components/_shared/variants/letter-spacing.ts @@ -1,11 +1,11 @@ const letterSpacingVariants = { - tightest: 'tracking-[-0.1em]', - tighter: 'tracking-tighter', - tight: 'tracking-tight', - base: 'tracking-normal', - wide: 'tracking-wide', - wider: 'tracking-wider', - widest: 'tracking-widest', + tightest: 'tracking-[-0.1em]', + tighter: 'tracking-tighter', + tight: 'tracking-tight', + base: 'tracking-normal', + wide: 'tracking-wide', + wider: 'tracking-wider', + widest: 'tracking-widest', } as const export { letterSpacingVariants } diff --git a/src/components/_shared/variants/text-break.ts b/src/components/_shared/variants/text-break.ts index 130d501..d77446e 100644 --- a/src/components/_shared/variants/text-break.ts +++ b/src/components/_shared/variants/text-break.ts @@ -1,8 +1,8 @@ const textBreakVariants = { - none: 'keep-all [overflow-wrap:normal]', - words: 'break-words [overflow-wrap:break-word]', - normal: 'break-normal [overflow-wrap:normal]', - all: 'break-all [overflow-wrap:anywhere]', + none: 'keep-all [overflow-wrap:normal]', + words: 'break-words [overflow-wrap:break-word]', + normal: 'break-normal [overflow-wrap:normal]', + all: 'break-all [overflow-wrap:anywhere]', } as const export { textBreakVariants } diff --git a/src/components/_shared/variants/text-overflow.ts b/src/components/_shared/variants/text-overflow.ts index e86cdb7..ba05541 100644 --- a/src/components/_shared/variants/text-overflow.ts +++ b/src/components/_shared/variants/text-overflow.ts @@ -1,6 +1,6 @@ const textOverflowVariants = { - elipsis: 'truncate', - clip: 'overflow-hidden whitespace-nowrap text-clip', + elipsis: 'truncate', + clip: 'overflow-hidden whitespace-nowrap text-clip', } as const export { textOverflowVariants } diff --git a/src/components/_shared/variants/text-shadow.ts b/src/components/_shared/variants/text-shadow.ts index 7ca0e5c..c55041d 100644 --- a/src/components/_shared/variants/text-shadow.ts +++ b/src/components/_shared/variants/text-shadow.ts @@ -1,9 +1,9 @@ const textShadowVariants = { - xs: '[&]:text-shadow-xs shadow-current', - sm: '[&]:text-shadow-sm shadow-current', - md: '[&]:text-shadow shadow-current', - lg: '[&]:text-shadow-lg shadow-current', - xl: '[&]:text-shadow-xs shadow-current', + xs: '[&]:text-shadow-xs shadow-current', + sm: '[&]:text-shadow-sm shadow-current', + md: '[&]:text-shadow shadow-current', + lg: '[&]:text-shadow-lg shadow-current', + xl: '[&]:text-shadow-xs shadow-current', } as const export { textShadowVariants } diff --git a/src/components/_shared/variants/text-size.ts b/src/components/_shared/variants/text-size.ts index ad4ebe2..132642f 100644 --- a/src/components/_shared/variants/text-size.ts +++ b/src/components/_shared/variants/text-size.ts @@ -1,18 +1,18 @@ const textSizeVariants = { - 'xs': 'text-xs', - 'sm': 'text-sm', - 'base': 'text-base', - 'md': 'text-1.0675rem leading-1.5675rem', - 'lg': 'text-lg', - 'xl': 'text-xl', - '2xl': 'text-2xl', - '3xl': 'text-3xl', - '4xl': 'text-4xl', - '5xl': 'text-5xl', - '6xl': 'text-6xl', - '7xl': 'text-7xl', - '8xl': 'text-8xl', - '9xl': 'text-9xl', + 'xs': 'text-xs', + 'sm': 'text-sm', + 'base': 'text-base', + 'md': 'text-1.0675rem leading-1.5675rem', + 'lg': 'text-lg', + 'xl': 'text-xl', + '2xl': 'text-2xl', + '3xl': 'text-3xl', + '4xl': 'text-4xl', + '5xl': 'text-5xl', + '6xl': 'text-6xl', + '7xl': 'text-7xl', + '8xl': 'text-8xl', + '9xl': 'text-9xl', } as const export { textSizeVariants } diff --git a/src/components/accordion/components/accordion-content.tsx b/src/components/accordion/components/accordion-content.tsx index 8cf02d3..0a06714 100644 --- a/src/components/accordion/components/accordion-content.tsx +++ b/src/components/accordion/components/accordion-content.tsx @@ -1,74 +1,74 @@ -"use client"; +'use client' -import { AccordionContent as AccordionContentPrimitive } from "@radix-ui/react-accordion"; -import { cn } from "@renderui/utils/cn"; -import { getOptionalObject } from "@renderui/utils/get-optional-object"; -import { polymorphic } from "@renderui/utils/polymorphic"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; -import React from "react"; +import { AccordionContent as AccordionContentPrimitive } from '@radix-ui/react-accordion' +import { cn } from '@renderui/utils/cn' +import { getOptionalObject } from '@renderui/utils/get-optional-object' +import { polymorphic } from '@renderui/utils/polymorphic' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' +import React from 'react' import { - DEFAULT_ACCORDION_CONTENT_CHILDREN_CONTAINER_CLASSNAME, - DEFAULT_ACCORDION_CONTENT_CLASSNAME, -} from "@/components/accordion/constants/constants"; -import { AccordionContentProps } from "@/components/accordion/types/accordion-content"; + DEFAULT_ACCORDION_CONTENT_CHILDREN_CONTAINER_CLASSNAME, + DEFAULT_ACCORDION_CONTENT_CLASSNAME, +} from '@/components/accordion/constants/constants' +import { AccordionContentProps } from '@/components/accordion/types/accordion-content' const AccordionContent = (props: AccordionContentProps) => { - const { - className, - style, - children, - childrenContainerProps, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - ...restProps - } = props; + const { + className, + style, + children, + childrenContainerProps, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + ...restProps + } = props - const { - asChild, - className: childrenContainerClassName, - ...restChildrenContainerProps - } = getOptionalObject(childrenContainerProps); + const { + asChild, + className: childrenContainerClassName, + ...restChildrenContainerProps + } = getOptionalObject(childrenContainerProps) - const AccordionContentChildrenContainer = polymorphic(asChild, "div"); + const AccordionContentChildrenContainer = polymorphic(asChild, 'div') - return ( - - - {children} - - - ); -}; + return ( + + + {children} + + + ) +} -AccordionContent.displayName = "AccordionContent"; +AccordionContent.displayName = 'AccordionContent' -export { AccordionContent }; +export { AccordionContent } diff --git a/src/components/accordion/components/accordion-item.tsx b/src/components/accordion/components/accordion-item.tsx index 79c0d6f..3951d42 100644 --- a/src/components/accordion/components/accordion-item.tsx +++ b/src/components/accordion/components/accordion-item.tsx @@ -1,22 +1,22 @@ -"use client"; +'use client' -import { AccordionItem as AccordionItemPrimitive } from "@radix-ui/react-accordion"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { AccordionItem as AccordionItemPrimitive } from '@radix-ui/react-accordion' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_ACCORDION_ITEM_CLASSNAME } from "@/components/accordion/constants/constants"; -import { AccordionItemProps } from "@/components/accordion/types/accordion-item"; +import { DEFAULT_ACCORDION_ITEM_CLASSNAME } from '@/components/accordion/constants/constants' +import { AccordionItemProps } from '@/components/accordion/types/accordion-item' const AccordionItem = (props: AccordionItemProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { AccordionItem }; +export { AccordionItem } diff --git a/src/components/accordion/components/accordion-trigger.tsx b/src/components/accordion/components/accordion-trigger.tsx index 7b9481e..65b4739 100644 --- a/src/components/accordion/components/accordion-trigger.tsx +++ b/src/components/accordion/components/accordion-trigger.tsx @@ -1,76 +1,75 @@ -"use client"; +'use client' import { - AccordionHeader as AccordionHeaderPrimitive, - AccordionTrigger as AccordionTriggerPrimitive, -} from "@radix-ui/react-accordion"; -import { cn, getOptionalObject } from "@renderui/utils"; -import React from "react"; + AccordionHeader as AccordionHeaderPrimitive, + AccordionTrigger as AccordionTriggerPrimitive, +} from '@radix-ui/react-accordion' +import { cn, getOptionalObject } from '@renderui/utils' +import React from 'react' -import { ChevronDownIcon } from "@/components/_shared/components/icons/chevron-down-icon"; +import { ChevronDownIcon } from '@/components/_shared/components/icons/chevron-down-icon' import { - DEFAULT_ACCORDION_HEADER_CLASSNAME, - DEFAULT_ACCORDION_TRIGGER_CLASSNAME, - DEFAULT_ACCORDION_TRIGGER_ICON_CLASSNAME, -} from "@/components/accordion/constants/constants"; -import { AccordionTriggerProps } from "@/components/accordion/types/accordion-trigger"; -import { Button } from "@/components/button"; + DEFAULT_ACCORDION_HEADER_CLASSNAME, + DEFAULT_ACCORDION_TRIGGER_CLASSNAME, + DEFAULT_ACCORDION_TRIGGER_ICON_CLASSNAME, +} from '@/components/accordion/constants/constants' +import { AccordionTriggerProps } from '@/components/accordion/types/accordion-trigger' +import { Button } from '@/components/button' const AccordionTrigger = (props: AccordionTriggerProps) => { - const { - ref, - className, - children, - icon, - iconProps, - accordionHeaderProps, - hasIcon = true, - hasRipple = false, - hasDefaultPressedStyles = false, - ...restProps - } = props; + const { + ref, + className, + children, + icon, + iconProps, + accordionHeaderProps, + hasIcon = true, + hasRipple = false, + hasDefaultPressedStyles = false, + ...restProps + } = props - const { className: headerClassName, ...restAccordionHeaderProps } = - getOptionalObject(accordionHeaderProps); + const { className: headerClassName, ...restAccordionHeaderProps } = + getOptionalObject(accordionHeaderProps) - const { className: iconClassName, ...restIconProps } = - getOptionalObject(iconProps); + const { className: iconClassName, ...restIconProps } = getOptionalObject(iconProps) - const renderIcon = () => { - if (!hasIcon) return null; + const renderIcon = () => { + if (!hasIcon) return null - if (icon) return icon; + if (icon) return icon - return ( - - ); - }; + return ( + + ) + } - return ( - - - - - - ); -}; + return ( + + + + + + ) +} -export { AccordionTrigger }; +export { AccordionTrigger } diff --git a/src/components/accordion/components/accordion.tsx b/src/components/accordion/components/accordion.tsx index 1218cc4..2afb87d 100644 --- a/src/components/accordion/components/accordion.tsx +++ b/src/components/accordion/components/accordion.tsx @@ -1,21 +1,21 @@ -"use client"; +'use client' -import { Accordion as AccordionPrimitive } from "@radix-ui/react-accordion"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { Accordion as AccordionPrimitive } from '@radix-ui/react-accordion' +import { cn } from '@renderui/utils' +import React from 'react' -import { AccordionProps } from "@/components/accordion/types/accordion"; +import { AccordionProps } from '@/components/accordion/types/accordion' const Accordion = (props: AccordionProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { Accordion }; +export { Accordion } diff --git a/src/components/accordion/constants/constants.ts b/src/components/accordion/constants/constants.ts index 69c98b3..351e320 100644 --- a/src/components/accordion/constants/constants.ts +++ b/src/components/accordion/constants/constants.ts @@ -1,25 +1,25 @@ const DEFAULT_ACCORDION_ITEM_CLASSNAME = - 'render-ui-accordion-item border-b border-mode-accent transition-[border] duration-fast' + 'render-ui-accordion-item border-b border-mode-accent transition-[border] duration-fast' const DEFAULT_ACCORDION_HEADER_CLASSNAME = 'render-ui-accordion-header flex' const DEFAULT_ACCORDION_TRIGGER_CLASSNAME = - 'render-ui-accordion-trigger flex flex-1 rounded-none items-center justify-between px-0 py-4 data-[focus-visible=true]:ring-offset-0 text-sm data-[hover=true]:underline [&[data-state=open]>svg]:rotate-180' + 'render-ui-accordion-trigger flex flex-1 rounded-none items-center justify-between px-0 py-4 data-[focus-visible=true]:ring-offset-0 text-sm data-[hover=true]:underline [&[data-state=open]>svg]:rotate-180' const DEFAULT_ACCORDION_TRIGGER_ICON_CLASSNAME = - 'render-ui-accordion-trigger-icon h-4 w-4 shrink-0 text-muted-foreground transition-[color,transform] duration-fast text-mode-contrast' + 'render-ui-accordion-trigger-icon h-4 w-4 shrink-0 text-muted-foreground transition-[color,transform] duration-fast text-mode-contrast' const DEFAULT_ACCORDION_CONTENT_CLASSNAME = - 'render-ui-accordion-content overflow-hidden text-sm text-mode-contrast data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down' + 'render-ui-accordion-content overflow-hidden text-sm text-mode-contrast data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down' const DEFAULT_ACCORDION_CONTENT_CHILDREN_CONTAINER_CLASSNAME = - 'render-ui-accordion-content-children-container pb-4 pt-0' + 'render-ui-accordion-content-children-container pb-4 pt-0' export { - DEFAULT_ACCORDION_CONTENT_CHILDREN_CONTAINER_CLASSNAME, - DEFAULT_ACCORDION_CONTENT_CLASSNAME, - DEFAULT_ACCORDION_HEADER_CLASSNAME, - DEFAULT_ACCORDION_ITEM_CLASSNAME, - DEFAULT_ACCORDION_TRIGGER_CLASSNAME, - DEFAULT_ACCORDION_TRIGGER_ICON_CLASSNAME, + DEFAULT_ACCORDION_CONTENT_CHILDREN_CONTAINER_CLASSNAME, + DEFAULT_ACCORDION_CONTENT_CLASSNAME, + DEFAULT_ACCORDION_HEADER_CLASSNAME, + DEFAULT_ACCORDION_ITEM_CLASSNAME, + DEFAULT_ACCORDION_TRIGGER_CLASSNAME, + DEFAULT_ACCORDION_TRIGGER_ICON_CLASSNAME, } diff --git a/src/components/accordion/types/accordion-content.ts b/src/components/accordion/types/accordion-content.ts index 3604fb5..b1f7ad8 100644 --- a/src/components/accordion/types/accordion-content.ts +++ b/src/components/accordion/types/accordion-content.ts @@ -1,24 +1,21 @@ -import { AccordionContent as AccordionContentPrimitive } from "@radix-ui/react-accordion"; -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { AccordionContent as AccordionContentPrimitive } from '@radix-ui/react-accordion' +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' -type AccordionContentPrimitiveType = typeof AccordionContentPrimitive; +type AccordionContentPrimitiveType = typeof AccordionContentPrimitive -type AccordionContentPrimitiveProps = - React.ComponentPropsWithRef; +type AccordionContentPrimitiveProps = React.ComponentPropsWithRef type AccordionContentChildrenContainerProps = { - childrenContainerProps?: Simplify< - React.ComponentPropsWithRef<"div"> & AsChildProp - >; - animationDuration?: number; -} & AnimationStyleVariables; + childrenContainerProps?: Simplify & AsChildProp> + animationDuration?: number +} & AnimationStyleVariables type AccordionContentProps = Simplify< - AccordionContentPrimitiveProps & AccordionContentChildrenContainerProps ->; + AccordionContentPrimitiveProps & AccordionContentChildrenContainerProps +> -export type { AccordionContentProps }; +export type { AccordionContentProps } diff --git a/src/components/accordion/types/accordion-item.ts b/src/components/accordion/types/accordion-item.ts index 363a8fb..bbf1da7 100644 --- a/src/components/accordion/types/accordion-item.ts +++ b/src/components/accordion/types/accordion-item.ts @@ -1,9 +1,8 @@ -import { AccordionItem as AccordionItemPrimitive } from "@radix-ui/react-accordion"; -import React from "react"; +import { AccordionItem as AccordionItemPrimitive } from '@radix-ui/react-accordion' +import React from 'react' -type AccordionItemPrimitiveType = typeof AccordionItemPrimitive; +type AccordionItemPrimitiveType = typeof AccordionItemPrimitive -type AccordionItemProps = - React.ComponentPropsWithRef; +type AccordionItemProps = React.ComponentPropsWithRef -export type { AccordionItemProps }; +export type { AccordionItemProps } diff --git a/src/components/accordion/types/accordion-trigger.ts b/src/components/accordion/types/accordion-trigger.ts index 6098c69..d3d1e9f 100644 --- a/src/components/accordion/types/accordion-trigger.ts +++ b/src/components/accordion/types/accordion-trigger.ts @@ -1,24 +1,20 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import { AccordionHeader as AccordionHeaderPrimitive } from "@radix-ui/react-accordion"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import { AccordionHeader as AccordionHeaderPrimitive } from '@radix-ui/react-accordion' +import React from 'react' -import { ChevronDownIcon } from "@/components/_shared/components/icons/chevron-down-icon"; -import { ButtonProps } from "@/components/button"; +import { ChevronDownIcon } from '@/components/_shared/components/icons/chevron-down-icon' +import { ButtonProps } from '@/components/button' -type AccordionTriggerButtonProps = Omit; +type AccordionTriggerButtonProps = Omit type AccordionTriggerTriggerProps = { - children?: React.ReactNode; - hasIcon?: boolean; - icon?: React.ReactNode; - iconProps?: React.ComponentPropsWithRef; - accordionHeaderProps?: React.ComponentPropsWithRef< - typeof AccordionHeaderPrimitive - >; -}; + children?: React.ReactNode + hasIcon?: boolean + icon?: React.ReactNode + iconProps?: React.ComponentPropsWithRef + accordionHeaderProps?: React.ComponentPropsWithRef +} -type AccordionTriggerProps = Simplify< - AccordionTriggerButtonProps & AccordionTriggerTriggerProps ->; +type AccordionTriggerProps = Simplify -export type { AccordionTriggerProps }; +export type { AccordionTriggerProps } diff --git a/src/components/accordion/types/accordion.ts b/src/components/accordion/types/accordion.ts index 18e7c99..513d7b9 100644 --- a/src/components/accordion/types/accordion.ts +++ b/src/components/accordion/types/accordion.ts @@ -1,7 +1,7 @@ -import { Accordion as AccordionPrimitive } from "@radix-ui/react-accordion"; +import { Accordion as AccordionPrimitive } from '@radix-ui/react-accordion' -type AccordionPrimitiveType = typeof AccordionPrimitive; +type AccordionPrimitiveType = typeof AccordionPrimitive -type AccordionProps = React.ComponentPropsWithRef; +type AccordionProps = React.ComponentPropsWithRef -export type { AccordionProps }; +export type { AccordionProps } diff --git a/src/components/aria/components/aria.tsx b/src/components/aria/components/aria.tsx index fe6260c..b5a6911 100644 --- a/src/components/aria/components/aria.tsx +++ b/src/components/aria/components/aria.tsx @@ -1,62 +1,59 @@ -"use client"; +'use client' -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { useAriaHandlers } from "@/components/_shared/hooks/use-aria-handlers"; -import { useMergedRef } from "@/components/_shared/hooks/use-merged-ref"; -import { splitAriaProps } from "@/components/_shared/utils/split-aria-props"; -import { DEFAULT_ARIA_CLASSNAME } from "@/components/aria/constants/constants"; -import { AriaProps } from "@/components/aria/types/aria"; +import { useAriaHandlers } from '@/components/_shared/hooks/use-aria-handlers' +import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' +import { splitAriaProps } from '@/components/_shared/utils/split-aria-props' +import { DEFAULT_ARIA_CLASSNAME } from '@/components/aria/constants/constants' +import { AriaProps } from '@/components/aria/types/aria' const Aria = (props: AriaProps) => { - const { ariaProps, nonAriaProps } = splitAriaProps(props); - - const internalRef = React.useRef(null); - const mergedRefCallback = useMergedRef([ - internalRef, - nonAriaProps.ref, - ]); - - const { - isPressDisabled, - isFocusDisabled, - isLongPressDisabled, - isHoverDisabled, - ...restAriaProps - } = ariaProps; - - const { - className, - isDisabled, - asChild, - isUsingAriaPressProps = false, - ...restNonAriaProps - } = nonAriaProps; - - const { ariaComponentProps } = useAriaHandlers( - { - ...restAriaProps, - isPressDisabled: isDisabled || isPressDisabled, - isFocusDisabled: isDisabled || isFocusDisabled, - isLongPressDisabled: isDisabled || isLongPressDisabled, - isHoverDisabled: isDisabled || isHoverDisabled, - isUsingAriaPressProps, - }, - internalRef - ); - - const Component = polymorphic(asChild, "div"); - - return ( - void} - className={cn(DEFAULT_ARIA_CLASSNAME, className)} - data-disabled={isDisabled} - {...restNonAriaProps} - {...ariaComponentProps} - /> - ); -}; - -export { Aria }; + const { ariaProps, nonAriaProps } = splitAriaProps(props) + + const internalRef = React.useRef(null) + const mergedRefCallback = useMergedRef([internalRef, nonAriaProps.ref]) + + const { + isPressDisabled, + isFocusDisabled, + isLongPressDisabled, + isHoverDisabled, + ...restAriaProps + } = ariaProps + + const { + className, + isDisabled, + asChild, + isUsingAriaPressProps = false, + ...restNonAriaProps + } = nonAriaProps + + const { ariaComponentProps } = useAriaHandlers( + { + ...restAriaProps, + isPressDisabled: isDisabled || isPressDisabled, + isFocusDisabled: isDisabled || isFocusDisabled, + isLongPressDisabled: isDisabled || isLongPressDisabled, + isHoverDisabled: isDisabled || isHoverDisabled, + isUsingAriaPressProps, + }, + internalRef, + ) + + const Component = polymorphic(asChild, 'div') + + return ( + void} + className={cn(DEFAULT_ARIA_CLASSNAME, className)} + data-disabled={isDisabled} + {...restNonAriaProps} + {...ariaComponentProps} + /> + ) +} + +export { Aria } diff --git a/src/components/aria/types/aria.ts b/src/components/aria/types/aria.ts index 97d866b..430fefb 100644 --- a/src/components/aria/types/aria.ts +++ b/src/components/aria/types/aria.ts @@ -1,16 +1,16 @@ -import React from "react"; +import React from 'react' -import { OptionalAriaProps } from "@/components/_shared/types/aria"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { OptionalAriaProps } from '@/components/_shared/types/aria' +import { Simplify } from '@/components/_shared/types/simplify' -type AriaPrimitiveProps = React.ComponentPropsWithRef<"div">; +type AriaPrimitiveProps = React.ComponentPropsWithRef<'div'> type AriaRenderUIProps = OptionalAriaProps & { - asChild?: boolean; - isDisabled?: boolean; - isUsingAriaPressProps?: boolean; -}; + asChild?: boolean + isDisabled?: boolean + isUsingAriaPressProps?: boolean +} -type AriaProps = Simplify; +type AriaProps = Simplify -export type { AriaProps }; +export type { AriaProps } diff --git a/src/components/aspect-ratio/components/aspect-ratio.tsx b/src/components/aspect-ratio/components/aspect-ratio.tsx index c82a0c7..893dd59 100644 --- a/src/components/aspect-ratio/components/aspect-ratio.tsx +++ b/src/components/aspect-ratio/components/aspect-ratio.tsx @@ -1,23 +1,17 @@ -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { AspectRatioProps } from "@/components/aspect-ratio/types/aspect-ratio"; -import { getMergedStyles } from "@/components/aspect-ratio/utils/get-merged-styles"; +import { AspectRatioProps } from '@/components/aspect-ratio/types/aspect-ratio' +import { getMergedStyles } from '@/components/aspect-ratio/utils/get-merged-styles' const AspectRatio = (props: AspectRatioProps) => { - const { asChild, ratio, className, style, ...restProps } = props; + const { asChild, ratio, className, style, ...restProps } = props - const { mergedClassName, mergedStyle } = getMergedStyles( - ratio, - className, - style - ); + const { mergedClassName, mergedStyle } = getMergedStyles(ratio, className, style) - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - ); -}; + return +} -export { AspectRatio }; +export { AspectRatio } diff --git a/src/components/aspect-ratio/types/aspect-ratio.ts b/src/components/aspect-ratio/types/aspect-ratio.ts index 388bf02..9f7ef49 100644 --- a/src/components/aspect-ratio/types/aspect-ratio.ts +++ b/src/components/aspect-ratio/types/aspect-ratio.ts @@ -1,16 +1,14 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React, { CSSProperties } from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React, { CSSProperties } from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type AspectRatioBoxProps = React.ComponentPropsWithRef<"div">; +type AspectRatioBoxProps = React.ComponentPropsWithRef<'div'> type AspectRatioRatioProps = { - ratio: CSSProperties["aspectRatio"]; -}; + ratio: CSSProperties['aspectRatio'] +} -type AspectRatioProps = Simplify< - AspectRatioBoxProps & AspectRatioRatioProps & AsChildProp ->; +type AspectRatioProps = Simplify -export type { AspectRatioProps }; +export type { AspectRatioProps } diff --git a/src/components/aspect-ratio/utils/get-merged-styles.ts b/src/components/aspect-ratio/utils/get-merged-styles.ts index 8b06671..4c89a4b 100644 --- a/src/components/aspect-ratio/utils/get-merged-styles.ts +++ b/src/components/aspect-ratio/utils/get-merged-styles.ts @@ -3,14 +3,14 @@ import { cn } from '@renderui/utils' import { AspectRatioProps } from '@/components/aspect-ratio/types/aspect-ratio' function getMergedStyles( - ratio: AspectRatioProps['ratio'], - className: AspectRatioProps['className'], - style: AspectRatioProps['style'], + ratio: AspectRatioProps['ratio'], + className: AspectRatioProps['className'], + style: AspectRatioProps['style'], ) { - return { - mergedClassName: cn('render-ui-aspect-ratio aspect-[var(--ratio)] overflow-hidden', className), - mergedStyle: ratio ? { '--ratio': ratio, ...style } : style, - } + return { + mergedClassName: cn('render-ui-aspect-ratio aspect-[var(--ratio)] overflow-hidden', className), + mergedStyle: ratio ? { '--ratio': ratio, ...style } : style, + } } export { getMergedStyles } diff --git a/src/components/box/components/box.tsx b/src/components/box/components/box.tsx index 8730b49..6b08357 100644 --- a/src/components/box/components/box.tsx +++ b/src/components/box/components/box.tsx @@ -1,20 +1,15 @@ -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { BoxProps } from "@/components/box/types/box"; -import { getMergedClassName } from "@/components/box/utils/get-merged-class-name"; +import { BoxProps } from '@/components/box/types/box' +import { getMergedClassName } from '@/components/box/utils/get-merged-class-name' const Box = (props: BoxProps) => { - const { asChild, className, grow, noShrink, ...restProps } = props; + const { asChild, className, grow, noShrink, ...restProps } = props - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - ); -}; + return +} -export { Box }; +export { Box } diff --git a/src/components/box/types/box.ts b/src/components/box/types/box.ts index efdd21d..b82c962 100644 --- a/src/components/box/types/box.ts +++ b/src/components/box/types/box.ts @@ -1,14 +1,14 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type BoxPrimitiveProps = React.ComponentPropsWithRef<"div">; +type BoxPrimitiveProps = React.ComponentPropsWithRef<'div'> type BoxCustomProps = { - grow?: boolean; - noShrink?: boolean; -}; + grow?: boolean + noShrink?: boolean +} -type BoxProps = Simplify; +type BoxProps = Simplify -export type { BoxProps }; +export type { BoxProps } diff --git a/src/components/box/utils/get-merged-class-name.ts b/src/components/box/utils/get-merged-class-name.ts index a16d595..ff97ddd 100644 --- a/src/components/box/utils/get-merged-class-name.ts +++ b/src/components/box/utils/get-merged-class-name.ts @@ -3,11 +3,11 @@ import { cn } from '@renderui/utils' import { BoxProps } from '@/components/box/types/box' function getMergedClassName( - className: BoxProps['className'], - grow: BoxProps['grow'], - noShrink: BoxProps['noShrink'], + className: BoxProps['className'], + grow: BoxProps['grow'], + noShrink: BoxProps['noShrink'], ) { - return cn('render-ui-box', grow ? 'grow' : '', noShrink ? 'shrink-0' : '', className) + return cn('render-ui-box', grow ? 'grow' : '', noShrink ? 'shrink-0' : '', className) } export { getMergedClassName } diff --git a/src/components/button/classes/button-classes.ts b/src/components/button/classes/button-classes.ts index edacc4f..6209a3e 100644 --- a/src/components/button/classes/button-classes.ts +++ b/src/components/button/classes/button-classes.ts @@ -1,104 +1,104 @@ import { cva } from '@renderui/utils' const buttonClasses = cva( - 'render-ui-button group relative box-border inline-flex cursor-pointer select-none appearance-none items-center justify-center gap-3 whitespace-nowrap rounded text-sm font-medium outline-none ring-ring-color ring-offset-background transition-[box-shadow,background-color,transform,opacity] duration-fast disabled:cursor-not-allowed disabled:opacity-40 data-[loading=true]:cursor-default [&_.render-ui-loader]:opacity-0', - { - variants: { - variant: { - plain: 'text-mode-foreground', - solid: '', - outline: '', - reveal: '', - text: 'data-[hover=true]:text-[rgba(var(--button-bg),0.8)]', - ghost: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.15)]', - shadow: 'shadow-lg [&]:shadow-[rgba(var(--button-bg),0.5)]', - }, - size: { - auto: '', - icon: 'apsect-square min-size-4 p-1', - sm: 'px-4.5 py-2 text-xs', - md: 'px-5 py-2.5 text-sm', - lg: 'px-7 py-3 text-base', - }, - hasDefaultFocusVisibleStyles: { - true: 'data-[focus-visible=true]:ring-ring-width data-[focus-visible=true]:ring-offset-offset', - false: '', - }, - hasRingOnAnyFocus: { - true: 'data-[focus=true]:ring-ring-width data-[focus=true]:ring-offset-offset', - false: '', - }, - hasDefaultPressedStyles: { - true: 'data-[pressed=true]:scale-[0.97]', - false: '', - }, - hasDefaultHoverStyles: { - true: '', - false: '', - }, - hasLowerOpacityOnLoading: { - true: 'data-[loading=true]:opacity-70', - false: '', - }, - hasLoaderOnLoading: { - true: '[&[data-loading=true]_.render-ui-loader]:opacity-100', - false: '', - }, - hasContentOnLoading: { - true: '[&[data-loading=true]_.render-ui-loader]:flex [&_.render-ui-loader]:hidden', - false: [ - '[&[data-loading=true]]:!text-transparent [&[data-loading=true]_*]:[transition:all_150ms,color_0s] [&[data-loading=true]_.render-ui-ripple]:opacity-100 [&[data-loading=true]_.render-ui-sub-layer]:opacity-100 [&[data-loading=true]_>_*]:opacity-0', - ], - }, - }, - compoundVariants: [ - { - variant: ['solid', 'shadow', 'outline', 'reveal'], - className: - 'before:pointer-events-none before:inset-0 before:inline-block before:size-full before:rounded-[inherit] before:content-[""]', - }, - { - variant: ['solid', 'shadow'], - className: - 'bg-[rgba(var(--button-bg))] text-[rgba(var(--button-color))] before:absolute before:z-[0] before:shadow-[shadow:inset_0_1px_theme(colors.white/15%)] after:pointer-events-none after:absolute after:inset-0 after:z-[0] after:inline-block after:size-full after:rounded-[inherit] after:ring after:ring-[0.5px] after:ring-inset after:ring-offset-[0px] after:content-[""] data-[color=mode-contrast]:before:hidden data-[color=mode]:before:hidden data-[color=mode-accent]:before:shadow-[shadow:inset_0_1px_theme(colors.white/10%)] data-[color=mode]:after:hidden [&]:after:ring-white/[5%]', - }, - { - hasDefaultHoverStyles: true, - variant: ['solid', 'shadow'], - className: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.8)]', - }, - { - variant: ['text', 'outline', 'ghost'], - className: - 'text-[rgba(var(--button-bg))] data-[pressed=true]:text-[rgba(var(--button-bg))]', - }, - { - hasDefaultHoverStyles: true, - variant: ['outline', 'reveal'], - className: - 'data-[hover=true]:before:ring-[rgba(var(--button-bg))] data-[hover=true]:data-[pressed=true]:before:ring-[rgba(var(--button-bg))]', - }, - { - variant: ['outline'], - className: - 'before:absolute before:ring before:ring-[1px] before:ring-inset before:ring-[rgba(var(--button-bg))] before:ring-offset-[0px] before:transition-[inherit] before:duration-[inherit]', - }, - { - hasDefaultHoverStyles: true, - variant: ['outline'], - className: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.1)]', - }, - { - variant: ['reveal'], - className: - 'text-[rgba(var(--mode-accent-foreground))] before:absolute before:ring before:ring-[1px] before:ring-inset before:ring-[rgba(var(--mode-accent))] before:ring-offset-[0px] before:transition-[inherit] before:duration-[inherit] ', - }, - { - variant: ['reveal'], - className: 'data-[hover=true]:text-[rgba(var(--button-bg))]', - }, - ], - }, + 'render-ui-button group relative box-border inline-flex cursor-pointer select-none appearance-none items-center justify-center gap-3 whitespace-nowrap rounded text-sm font-medium outline-none ring-ring-color ring-offset-background transition-[box-shadow,background-color,transform,opacity] duration-fast disabled:cursor-not-allowed disabled:opacity-40 data-[loading=true]:cursor-default [&_.render-ui-loader]:opacity-0', + { + variants: { + variant: { + plain: 'text-mode-foreground', + solid: '', + outline: '', + reveal: '', + text: 'data-[hover=true]:text-[rgba(var(--button-bg),0.8)]', + ghost: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.15)]', + shadow: 'shadow-lg [&]:shadow-[rgba(var(--button-bg),0.5)]', + }, + size: { + auto: '', + icon: 'apsect-square min-size-4 p-1', + sm: 'px-4.5 py-2 text-xs', + md: 'px-5 py-2.5 text-sm', + lg: 'px-7 py-3 text-base', + }, + hasDefaultFocusVisibleStyles: { + true: 'data-[focus-visible=true]:ring-ring-width data-[focus-visible=true]:ring-offset-offset', + false: '', + }, + hasRingOnAnyFocus: { + true: 'data-[focus=true]:ring-ring-width data-[focus=true]:ring-offset-offset', + false: '', + }, + hasDefaultPressedStyles: { + true: 'data-[pressed=true]:scale-[0.97]', + false: '', + }, + hasDefaultHoverStyles: { + true: '', + false: '', + }, + hasLowerOpacityOnLoading: { + true: 'data-[loading=true]:opacity-70', + false: '', + }, + hasLoaderOnLoading: { + true: '[&[data-loading=true]_.render-ui-loader]:opacity-100', + false: '', + }, + hasContentOnLoading: { + true: '[&[data-loading=true]_.render-ui-loader]:flex [&_.render-ui-loader]:hidden', + false: [ + '[&[data-loading=true]]:!text-transparent [&[data-loading=true]_*]:[transition:all_150ms,color_0s] [&[data-loading=true]_.render-ui-ripple]:opacity-100 [&[data-loading=true]_.render-ui-sub-layer]:opacity-100 [&[data-loading=true]_>_*]:opacity-0', + ], + }, + }, + compoundVariants: [ + { + variant: ['solid', 'shadow', 'outline', 'reveal'], + className: + 'before:pointer-events-none before:inset-0 before:inline-block before:size-full before:rounded-[inherit] before:content-[""]', + }, + { + variant: ['solid', 'shadow'], + className: + 'bg-[rgba(var(--button-bg))] text-[rgba(var(--button-color))] before:absolute before:z-[0] before:shadow-[shadow:inset_0_1px_theme(colors.white/15%)] after:pointer-events-none after:absolute after:inset-0 after:z-[0] after:inline-block after:size-full after:rounded-[inherit] after:ring after:ring-[0.5px] after:ring-inset after:ring-offset-[0px] after:content-[""] data-[color=mode-contrast]:before:hidden data-[color=mode]:before:hidden data-[color=mode-accent]:before:shadow-[shadow:inset_0_1px_theme(colors.white/10%)] data-[color=mode]:after:hidden [&]:after:ring-white/[5%]', + }, + { + hasDefaultHoverStyles: true, + variant: ['solid', 'shadow'], + className: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.8)]', + }, + { + variant: ['text', 'outline', 'ghost'], + className: + 'text-[rgba(var(--button-bg))] data-[pressed=true]:text-[rgba(var(--button-bg))]', + }, + { + hasDefaultHoverStyles: true, + variant: ['outline', 'reveal'], + className: + 'data-[hover=true]:before:ring-[rgba(var(--button-bg))] data-[hover=true]:data-[pressed=true]:before:ring-[rgba(var(--button-bg))]', + }, + { + variant: ['outline'], + className: + 'before:absolute before:ring before:ring-[1px] before:ring-inset before:ring-[rgba(var(--button-bg))] before:ring-offset-[0px] before:transition-[inherit] before:duration-[inherit]', + }, + { + hasDefaultHoverStyles: true, + variant: ['outline'], + className: 'data-[hover=true]:bg-[rgba(var(--button-bg),0.1)]', + }, + { + variant: ['reveal'], + className: + 'text-[rgba(var(--mode-accent-foreground))] before:absolute before:ring before:ring-[1px] before:ring-inset before:ring-[rgba(var(--mode-accent))] before:ring-offset-[0px] before:transition-[inherit] before:duration-[inherit] ', + }, + { + variant: ['reveal'], + className: 'data-[hover=true]:text-[rgba(var(--button-bg))]', + }, + ], + }, ) export { buttonClasses } diff --git a/src/components/button/components/button.tsx b/src/components/button/components/button.tsx index 3083b37..990326d 100644 --- a/src/components/button/components/button.tsx +++ b/src/components/button/components/button.tsx @@ -1,83 +1,80 @@ -"use client"; +'use client' -import { functionCallOrValue } from "@renderui/utils/function-call-or-value"; -import { polymorphic } from "@renderui/utils/polymorphic"; -import React from "react"; +import { functionCallOrValue } from '@renderui/utils/function-call-or-value' +import { polymorphic } from '@renderui/utils/polymorphic' +import React from 'react' -import { useButton } from "@/components/button/hooks/use-button"; -import { ButtonProps } from "@/components/button/types/button"; +import { useButton } from '@/components/button/hooks/use-button' +import { ButtonProps } from '@/components/button/types/button' const Loader = React.lazy(() => - import("@/components/loader/components/loader").then((module) => ({ - default: module.Loader, - })) -); + import('@/components/loader/components/loader').then((module) => ({ + default: module.Loader, + })), +) const Ripple = React.lazy(() => - import("@/components/ripple/components/ripple").then((module) => ({ - default: module.Ripple, - })) -); + import('@/components/ripple/components/ripple').then((module) => ({ + default: module.Ripple, + })), +) const Button = (props: ButtonProps) => { - const { buttonProps, subLayerProps, rippleProps, loaderProps, utility } = - useButton(props); + const { buttonProps, subLayerProps, rippleProps, loaderProps, utility } = useButton(props) - const { children } = buttonProps; - const { - asChild, - isPressed, - isKeyboardPressed, - isLoading, - loader, - loaderPosition, - hasLoaderOnLoading, - startContent, - endContent, - loadingContent, - hasRipple, - } = utility; + const { children } = buttonProps + const { + asChild, + isPressed, + isKeyboardPressed, + isLoading, + loader, + loaderPosition, + hasLoaderOnLoading, + startContent, + endContent, + loadingContent, + hasRipple, + } = utility - const Component = polymorphic(asChild, "button"); + const Component = polymorphic(asChild, 'button') - const getChildren = () => { - return isLoading && loadingContent - ? functionCallOrValue(loadingContent, { - isPressed, - isKeyboardPressed, - Loader: Loader, - Ripple: Ripple, - }) - : functionCallOrValue(children, { - isPressed, - isKeyboardPressed, - Loader: Loader, - Ripple: Ripple, - }); - }; + const getChildren = () => { + return isLoading && loadingContent + ? functionCallOrValue(loadingContent, { + isPressed, + isKeyboardPressed, + Loader: Loader, + Ripple: Ripple, + }) + : functionCallOrValue(children, { + isPressed, + isKeyboardPressed, + Loader: Loader, + Ripple: Ripple, + }) + } - const getContent = () => { - if (asChild) return getChildren(); + const getContent = () => { + if (asChild) return getChildren() - return ( - <> - {functionCallOrValue(startContent, { isPressed, isKeyboardPressed })} - {isLoading && hasLoaderOnLoading && loaderPosition === "start" - ? loader ?? - : null} - {getChildren()} - {isLoading && hasLoaderOnLoading && loaderPosition === "end" - ? loader ?? - : null} - {functionCallOrValue(endContent, { isPressed, isKeyboardPressed })} - {hasRipple ? ( - - ) : null} - - ); - }; + return ( + <> + {functionCallOrValue(startContent, { isPressed, isKeyboardPressed })} + {isLoading && hasLoaderOnLoading && loaderPosition === 'start' + ? loader ?? + : null} + {getChildren()} + {isLoading && hasLoaderOnLoading && loaderPosition === 'end' + ? loader ?? + : null} + {functionCallOrValue(endContent, { isPressed, isKeyboardPressed })} + {hasRipple ? : null} + + ) + } - return {getContent()}; -}; + return {getContent()} +} -export { Button }; +export { Button } diff --git a/src/components/button/hooks/use-button.ts b/src/components/button/hooks/use-button.ts index b5c46b0..f33d1ee 100644 --- a/src/components/button/hooks/use-button.ts +++ b/src/components/button/hooks/use-button.ts @@ -1,135 +1,135 @@ -import { chain } from "@renderui/utils/chain"; -import { cn } from "@renderui/utils/cn"; -import React from "react"; +import { chain } from '@renderui/utils/chain' +import { cn } from '@renderui/utils/cn' +import React from 'react' -import { useAriaHandlers } from "@/components/_shared/hooks/use-aria-handlers"; -import { useMergedRef } from "@/components/_shared/hooks/use-merged-ref"; -import { splitAriaProps } from "@/components/_shared/utils/split-aria-props"; -import { buttonClasses } from "@/components/button/classes/button-classes"; -import { ButtonProps } from "@/components/button/types/button"; -import { getColorVariables } from "@/components/button/utils/get-color-variables"; -import { getLoaderProps } from "@/components/button/utils/get-loader-props"; -import { getRippleProps } from "@/components/button/utils/get-ripple-props"; +import { useAriaHandlers } from '@/components/_shared/hooks/use-aria-handlers' +import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' +import { splitAriaProps } from '@/components/_shared/utils/split-aria-props' +import { buttonClasses } from '@/components/button/classes/button-classes' +import { ButtonProps } from '@/components/button/types/button' +import { getColorVariables } from '@/components/button/utils/get-color-variables' +import { getLoaderProps } from '@/components/button/utils/get-loader-props' +import { getRippleProps } from '@/components/button/utils/get-ripple-props' function useButton(props: ButtonProps) { - const { ariaProps, nonAriaProps } = splitAriaProps(props); - const { - ref, - asChild, - className, - style, - isDisabled, - isLoading, - startContent, - endContent, - loadingContent, - loaderProps, - loaderRef, - subLayerProps, - rippleProps, - rippleRef, - loader, - type = "button", - size = "md", - variant = "solid", - color = "primary", - loaderPosition = "end", - hasLoaderOnLoading = true, - hasRipple = true, - hasDefaultHoverStyles = true, - hasDefaultFocusVisibleStyles = true, - hasDefaultPressedStyles = true, - hasRingOnAnyFocus = false, - hasLowerOpacityOnLoading = true, - hasContentOnLoading = true, - onClick, - ...restProps - } = nonAriaProps; + const { ariaProps, nonAriaProps } = splitAriaProps(props) + const { + ref, + asChild, + className, + style, + isDisabled, + isLoading, + startContent, + endContent, + loadingContent, + loaderProps, + loaderRef, + subLayerProps, + rippleProps, + rippleRef, + loader, + type = 'button', + size = 'md', + variant = 'solid', + color = 'primary', + loaderPosition = 'end', + hasLoaderOnLoading = true, + hasRipple = true, + hasDefaultHoverStyles = true, + hasDefaultFocusVisibleStyles = true, + hasDefaultPressedStyles = true, + hasRingOnAnyFocus = false, + hasLowerOpacityOnLoading = true, + hasContentOnLoading = true, + onClick, + ...restProps + } = nonAriaProps - const internalRef = React.useRef(null); - const mergedRefs = useMergedRef([internalRef, ref]); + const internalRef = React.useRef(null) + const mergedRefs = useMergedRef([internalRef, ref]) - const isPressDisabled = isDisabled || ariaProps?.isPressDisabled || isLoading; - const isHoverDisabled = isDisabled || ariaProps?.isHoverDisabled || isLoading; + const isPressDisabled = isDisabled || ariaProps?.isPressDisabled || isLoading + const isHoverDisabled = isDisabled || ariaProps?.isHoverDisabled || isLoading - const { ariaComponentProps, ariaFlags } = useAriaHandlers( - { - ...ariaProps, - onPress: chain(ariaProps.onPress, onClick), - isPressDisabled, - isHoverDisabled, - }, - internalRef - ); - const { isPressed, isKeyboardPressed } = ariaFlags; + const { ariaComponentProps, ariaFlags } = useAriaHandlers( + { + ...ariaProps, + onPress: chain(ariaProps.onPress, onClick), + isPressDisabled, + isHoverDisabled, + }, + internalRef, + ) + const { isPressed, isKeyboardPressed } = ariaFlags - const mergedLoaderProps = getLoaderProps({ - loaderRef, - loaderProps, - isLoading, - }); + const mergedLoaderProps = getLoaderProps({ + loaderRef, + loaderProps, + isLoading, + }) - const hasContent = () => { - if (mergedLoaderProps.position === "absolute-center") return false; + const hasContent = () => { + if (mergedLoaderProps.position === 'absolute-center') return false - return hasContentOnLoading; - }; + return hasContentOnLoading + } - const memoizedStyleWithColorVariable = React.useMemo( - () => ({ - ...style, - ...getColorVariables(color), - }), - [style, color] - ); + const memoizedStyleWithColorVariable = React.useMemo( + () => ({ + ...style, + ...getColorVariables(color), + }), + [style, color], + ) - return { - buttonProps: { - type, - ref: mergedRefs, - disabled: isDisabled, - className: cn( - buttonClasses({ - size, - variant, - hasRingOnAnyFocus, - hasDefaultFocusVisibleStyles, - hasDefaultPressedStyles, - hasDefaultHoverStyles, - hasLowerOpacityOnLoading, - hasLoaderOnLoading, - hasContentOnLoading: hasContent(), - }), - className - ), - style: memoizedStyleWithColorVariable, - "aria-label": isLoading ? "loading" : undefined, - "aria-busy": isLoading || undefined, - "data-variant": variant, - "data-color": color, - "data-loading": isLoading || undefined, - "data-disabled": isDisabled, - "data-slot": "base", - ...ariaComponentProps, - ...restProps, - }, - subLayerProps, - rippleProps: getRippleProps({ rippleRef, rippleProps, isLoading }), - loaderProps: mergedLoaderProps, - utility: { - asChild, - isPressed, - isKeyboardPressed, - isLoading, - startContent, - endContent, - loadingContent, - loader, - loaderPosition, - hasRipple, - hasLoaderOnLoading, - }, - }; + return { + buttonProps: { + type, + ref: mergedRefs, + disabled: isDisabled, + className: cn( + buttonClasses({ + size, + variant, + hasRingOnAnyFocus, + hasDefaultFocusVisibleStyles, + hasDefaultPressedStyles, + hasDefaultHoverStyles, + hasLowerOpacityOnLoading, + hasLoaderOnLoading, + hasContentOnLoading: hasContent(), + }), + className, + ), + style: memoizedStyleWithColorVariable, + 'aria-label': isLoading ? 'loading' : undefined, + 'aria-busy': isLoading || undefined, + 'data-variant': variant, + 'data-color': color, + 'data-loading': isLoading || undefined, + 'data-disabled': isDisabled, + 'data-slot': 'base', + ...ariaComponentProps, + ...restProps, + }, + subLayerProps, + rippleProps: getRippleProps({ rippleRef, rippleProps, isLoading }), + loaderProps: mergedLoaderProps, + utility: { + asChild, + isPressed, + isKeyboardPressed, + isLoading, + startContent, + endContent, + loadingContent, + loader, + loaderPosition, + hasRipple, + hasLoaderOnLoading, + }, + } } -export { useButton }; +export { useButton } diff --git a/src/components/button/hooks/use-lazy-components.ts b/src/components/button/hooks/use-lazy-components.ts index 3c57b71..a94ca1c 100644 --- a/src/components/button/hooks/use-lazy-components.ts +++ b/src/components/button/hooks/use-lazy-components.ts @@ -6,35 +6,35 @@ import { Loader } from '@/components/loader' import { Ripple } from '@/components/ripple' type UseLazyComponentsProps = Pick< - ButtonProps, - 'isLoading' | 'hasLoaderOnLoading' | 'loader' | 'hasRipple' + ButtonProps, + 'isLoading' | 'hasLoaderOnLoading' | 'loader' | 'hasRipple' > function useLazyComponents(props: UseLazyComponentsProps) { - const { isLoading, hasLoaderOnLoading, loader, hasRipple } = props + const { isLoading, hasLoaderOnLoading, loader, hasRipple } = props - const [LoaderComponent, setLoaderComponent] = React.useState(null) - const [RippleComponent, setRippleComponent] = React.useState(null) + const [LoaderComponent, setLoaderComponent] = React.useState(null) + const [RippleComponent, setRippleComponent] = React.useState(null) - React.useEffect(() => { - const loadComponents = async () => { - if (isLoading && hasLoaderOnLoading && !loader) { - const { Loader } = await import('@/components/loader') + React.useEffect(() => { + const loadComponents = async () => { + if (isLoading && hasLoaderOnLoading && !loader) { + const { Loader } = await import('@/components/loader') - setLoaderComponent(Loader) - } + setLoaderComponent(Loader) + } - if (hasRipple) { - const { Ripple } = await import('@/components/ripple') + if (hasRipple) { + const { Ripple } = await import('@/components/ripple') - setRippleComponent(Ripple) - } - } + setRippleComponent(Ripple) + } + } - loadComponents() - }, [isLoading, loader, hasLoaderOnLoading, hasRipple]) + loadComponents() + }, [isLoading, loader, hasLoaderOnLoading, hasRipple]) - return { LoaderComponent, RippleComponent } + return { LoaderComponent, RippleComponent } } export { useLazyComponents } diff --git a/src/components/button/types/button.ts b/src/components/button/types/button.ts index 2d7c80a..6a98fd0 100644 --- a/src/components/button/types/button.ts +++ b/src/components/button/types/button.ts @@ -1,65 +1,61 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; - -import { OptionalAriaProps } from "@/components/_shared/types/aria"; -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { Color } from "@/components/_shared/types/colors"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { buttonClasses } from "@/components/button/classes/button-classes"; -import { LoaderProps, LoaderRef } from "@/components/loader"; -import { RippleProps, RippleRef } from "@/components/ripple"; -import { useLazyComponents } from "@/components/button/hooks/use-lazy-components"; -import { SubLayerProps } from "@/components/sub-layer"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' + +import { OptionalAriaProps } from '@/components/_shared/types/aria' +import { AsChildProp } from '@/components/_shared/types/as-child' +import { Color } from '@/components/_shared/types/colors' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { buttonClasses } from '@/components/button/classes/button-classes' +import { LoaderProps, LoaderRef } from '@/components/loader' +import { RippleProps, RippleRef } from '@/components/ripple' +import { useLazyComponents } from '@/components/button/hooks/use-lazy-components' +import { SubLayerProps } from '@/components/sub-layer' type ButtonPrimitiveProps = Omit< - React.ComponentPropsWithRef<"button">, - "children" | "disabled" | "color" ->; + React.ComponentPropsWithRef<'button'>, + 'children' | 'disabled' | 'color' +> type ButtonContentRenderPropsProps = { - isPressed?: boolean; - isKeyboardPressed?: boolean; -}; + isPressed?: boolean + isKeyboardPressed?: boolean +} type ButtonChildrenRenderPropsProps = ButtonContentRenderPropsProps & { - Loader: ReturnType["LoaderComponent"]; - Ripple: ReturnType["RippleComponent"]; -}; + Loader: ReturnType['LoaderComponent'] + Ripple: ReturnType['RippleComponent'] +} type ButtonContentRenderProps = - | ((props: ButtonContentRenderPropsProps) => React.ReactNode) - | React.ReactNode; + | ((props: ButtonContentRenderPropsProps) => React.ReactNode) + | React.ReactNode type ButtonChildrenRenderProps = - | ((props: ButtonChildrenRenderPropsProps) => React.ReactNode) - | React.ReactNode; + | ((props: ButtonChildrenRenderPropsProps) => React.ReactNode) + | React.ReactNode type ButtonCustomProps = { - children?: ButtonChildrenRenderProps; - loadingContent?: ButtonChildrenRenderProps; - startContent?: ButtonContentRenderProps; - endContent?: ButtonContentRenderProps; - hasRipple?: boolean; - isDisabled?: boolean; - isLoading?: boolean; - color?: Color; - loaderPosition?: "start" | "end"; - loaderProps?: LoaderProps; - loaderRef?: React.Ref; - loader?: React.ReactNode; - subLayerProps?: SubLayerProps; - rippleProps?: RippleProps; - rippleRef?: React.Ref; -}; - -type ButtoVariantProps = NonNullableVariantProps; + children?: ButtonChildrenRenderProps + loadingContent?: ButtonChildrenRenderProps + startContent?: ButtonContentRenderProps + endContent?: ButtonContentRenderProps + hasRipple?: boolean + isDisabled?: boolean + isLoading?: boolean + color?: Color + loaderPosition?: 'start' | 'end' + loaderProps?: LoaderProps + loaderRef?: React.Ref + loader?: React.ReactNode + subLayerProps?: SubLayerProps + rippleProps?: RippleProps + rippleRef?: React.Ref +} + +type ButtoVariantProps = NonNullableVariantProps type ButtonProps = Simplify< - ButtonPrimitiveProps & - ButtonCustomProps & - ButtoVariantProps & - OptionalAriaProps & - AsChildProp ->; + ButtonPrimitiveProps & ButtonCustomProps & ButtoVariantProps & OptionalAriaProps & AsChildProp +> -export type { ButtonProps }; +export type { ButtonProps } diff --git a/src/components/button/utils/get-color-variables.ts b/src/components/button/utils/get-color-variables.ts index 189d365..564e779 100644 --- a/src/components/button/utils/get-color-variables.ts +++ b/src/components/button/utils/get-color-variables.ts @@ -3,9 +3,9 @@ import React from 'react' import { Color } from '@/components/_shared/types/colors' const getColorVariables = (color: Color) => - ({ - '--button-bg': `var(--${color})`, - '--button-color': `var(--${color}-foreground)`, - }) as React.CSSProperties + ({ + '--button-bg': `var(--${color})`, + '--button-color': `var(--${color}-foreground)`, + }) as React.CSSProperties export { getColorVariables } diff --git a/src/components/button/utils/get-loader-props.ts b/src/components/button/utils/get-loader-props.ts index 98010cb..bf8c3a8 100644 --- a/src/components/button/utils/get-loader-props.ts +++ b/src/components/button/utils/get-loader-props.ts @@ -4,27 +4,27 @@ import React from 'react' import { LoaderProps } from '@/components/loader' type GetLoaderPropsArgs = { - loaderRef: React.Ref | undefined - loaderProps: LoaderProps | undefined - isLoading: boolean | undefined + loaderRef: React.Ref | undefined + loaderProps: LoaderProps | undefined + isLoading: boolean | undefined } const getLoaderProps = (args: GetLoaderPropsArgs) => { - const { loaderRef, loaderProps, isLoading } = args + const { loaderRef, loaderProps, isLoading } = args - const { - className, - position = 'absolute-center', - ...restLoaderProps - } = getOptionalObject(loaderProps) + const { + className, + position = 'absolute-center', + ...restLoaderProps + } = getOptionalObject(loaderProps) - return { - 'ref': loaderRef, - 'data-slot': 'loader', - position, - 'className': cx(isLoading ? 'text-[rgba(var(--button-color))]' : undefined, className), - ...restLoaderProps, - } + return { + 'ref': loaderRef, + 'data-slot': 'loader', + position, + 'className': cx(isLoading ? 'text-[rgba(var(--button-color))]' : undefined, className), + ...restLoaderProps, + } } export { getLoaderProps } diff --git a/src/components/button/utils/get-ripple-props.ts b/src/components/button/utils/get-ripple-props.ts index a2ae746..170c94b 100644 --- a/src/components/button/utils/get-ripple-props.ts +++ b/src/components/button/utils/get-ripple-props.ts @@ -4,30 +4,30 @@ import { RippleProps, RippleRef } from '@/components/ripple' // @TODO understand type problem and fix it, remove any's type GetRipplePropsArgs = { - rippleRef: React.Ref | undefined - rippleProps: RippleProps | undefined - isLoading: boolean | undefined + rippleRef: React.Ref | undefined + rippleProps: RippleProps | undefined + isLoading: boolean | undefined } const getRippleProps = (args: any): any => { - const { rippleRef, rippleProps, isLoading } = args + const { rippleRef, rippleProps, isLoading } = args - const { - color: colorProp, - className, - isDisabled: isDisabledProp, - ...restRippleProps - } = getOptionalObject(rippleProps) + const { + color: colorProp, + className, + isDisabled: isDisabledProp, + ...restRippleProps + } = getOptionalObject(rippleProps) - const isDisabled = isLoading ?? isDisabledProp + const isDisabled = isLoading ?? isDisabledProp - return { - 'ref': rippleRef, - 'data-slot': 'ripple', - 'className': cx(isLoading ? '!text-[rgba(var(--button-color))]' : undefined, className), - isDisabled, - ...restRippleProps, - } + return { + 'ref': rippleRef, + 'data-slot': 'ripple', + 'className': cx(isLoading ? '!text-[rgba(var(--button-color))]' : undefined, className), + isDisabled, + ...restRippleProps, + } } export { getRippleProps } diff --git a/src/components/card/classes/card-classes.ts b/src/components/card/classes/card-classes.ts index 75264b2..3ab2016 100644 --- a/src/components/card/classes/card-classes.ts +++ b/src/components/card/classes/card-classes.ts @@ -1,23 +1,23 @@ import { cva } from '@renderui/utils' const cardClasses = cva( - 'render-ui-card dark:border-mode-accent-high relative flex w-fit flex-col justify-between overflow-hidden rounded-lg border border-mode-accent bg-card text-foreground shadow-sm transition-all duration-fast', - { - variants: { - hasShadowOnHover: { - true: 'hover:shadow', - false: '', - }, - isBlurred: { - true: ['bg-foreground/80', 'backdrop-blur-md', 'backdrop-saturate-150'], - false: [], - }, - }, - defaultVariants: { - isBlurred: false, - hasShadowOnHover: false, - }, - }, + 'render-ui-card dark:border-mode-accent-high relative flex w-fit flex-col justify-between overflow-hidden rounded-lg border border-mode-accent bg-card text-foreground shadow-sm transition-all duration-fast', + { + variants: { + hasShadowOnHover: { + true: 'hover:shadow', + false: '', + }, + isBlurred: { + true: ['bg-foreground/80', 'backdrop-blur-md', 'backdrop-saturate-150'], + false: [], + }, + }, + defaultVariants: { + isBlurred: false, + hasShadowOnHover: false, + }, + }, ) export { cardClasses } diff --git a/src/components/card/components/card-body.tsx b/src/components/card/components/card-body.tsx index 7282f06..c96835e 100644 --- a/src/components/card/components/card-body.tsx +++ b/src/components/card/components/card-body.tsx @@ -1,21 +1,21 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { DEFAULT_CARD_BODY_CLASSNAME } from "@/components/card/constants/constants"; -import { CardBodyProps } from "@/components/card/types/card-body"; +import { DEFAULT_CARD_BODY_CLASSNAME } from '@/components/card/constants/constants' +import { CardBodyProps } from '@/components/card/types/card-body' const CardBody = (props: CardBodyProps) => { - const { asChild, className, ...restProps } = props; + const { asChild, className, ...restProps } = props - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - ); -}; + return ( + + ) +} -export { CardBody }; +export { CardBody } diff --git a/src/components/card/components/card-description.tsx b/src/components/card/components/card-description.tsx index fe880b9..98d477a 100644 --- a/src/components/card/components/card-description.tsx +++ b/src/components/card/components/card-description.tsx @@ -1,21 +1,21 @@ -import { cn } from "@renderui/utils"; -import React from "react"; +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_CARD_DESCRIPTION_CLASSNAME } from "@/components/card/constants/constants"; -import { CardDescriptionProps } from "@/components/card/types/card-description"; -import { Text } from "@/components/text"; +import { DEFAULT_CARD_DESCRIPTION_CLASSNAME } from '@/components/card/constants/constants' +import { CardDescriptionProps } from '@/components/card/types/card-description' +import { Text } from '@/components/text' const CardDescription = (props: CardDescriptionProps) => { - const { className, size = "sm", ...restProps } = props; + const { className, size = 'sm', ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { CardDescription }; +export { CardDescription } diff --git a/src/components/card/components/card-footer.tsx b/src/components/card/components/card-footer.tsx index b0d68e7..0220c13 100644 --- a/src/components/card/components/card-footer.tsx +++ b/src/components/card/components/card-footer.tsx @@ -1,59 +1,52 @@ -import { cn, getOptionalObject, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, getOptionalObject, polymorphic } from '@renderui/utils' +import React from 'react' import { - DEFAULT_CARD_FOOTER_CHILDREN_CLASSNAME, - DEFAULT_CARD_FOOTER_CLASSNAME, -} from "@/components/card/constants/constants"; -import { CardFooterProps } from "@/components/card/types/card-footer"; + DEFAULT_CARD_FOOTER_CHILDREN_CLASSNAME, + DEFAULT_CARD_FOOTER_CLASSNAME, +} from '@/components/card/constants/constants' +import { CardFooterProps } from '@/components/card/types/card-footer' const CardFooter = (props: CardFooterProps) => { - const { - asChild, - childrenContainerProps, - contentClassName, - childrenClassName, - startContent, - endContent, - children, - ...restProps - } = props; + const { + asChild, + childrenContainerProps, + contentClassName, + childrenClassName, + startContent, + endContent, + children, + ...restProps + } = props - const { - asChild: childrenContainerAsChild, - className: childrenContainerClassName, - ...restChildrenContainerProps - } = getOptionalObject(childrenContainerProps); + const { + asChild: childrenContainerAsChild, + className: childrenContainerClassName, + ...restChildrenContainerProps + } = getOptionalObject(childrenContainerProps) - const ContentComponent = polymorphic(asChild, "div"); + const ContentComponent = polymorphic(asChild, 'div') - const ChildrenContainerComponent = polymorphic( - childrenContainerAsChild, - "span" - ); + const ChildrenContainerComponent = polymorphic(childrenContainerAsChild, 'span') - return ( - - {startContent} - - {children} - - {endContent} - - ); -}; + return ( + + {startContent} + + {children} + + {endContent} + + ) +} -export { CardFooter }; +export { CardFooter } diff --git a/src/components/card/components/card-header.tsx b/src/components/card/components/card-header.tsx index 40f79cc..a7bb5fd 100644 --- a/src/components/card/components/card-header.tsx +++ b/src/components/card/components/card-header.tsx @@ -1,58 +1,55 @@ -import { cn, getOptionalObject, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, getOptionalObject, polymorphic } from '@renderui/utils' +import React from 'react' import { - DEFAULT_CARD_HEADER_CHILDREN_CLASSNAME, - DEFAULT_CARD_HEADER_CONTENT_CLASSNAME, -} from "@/components/card/constants/constants"; -import { CardHeaderProps } from "@/components/card/types/card-header"; + DEFAULT_CARD_HEADER_CHILDREN_CLASSNAME, + DEFAULT_CARD_HEADER_CONTENT_CLASSNAME, +} from '@/components/card/constants/constants' +import { CardHeaderProps } from '@/components/card/types/card-header' const CardHeader = (props: CardHeaderProps) => { - const { - asChild, - childrenContainerProps, - contentClassName, - childrenClassName, - startContent, - endContent, - children, - ...restProps - } = props; + const { + asChild, + childrenContainerProps, + contentClassName, + childrenClassName, + startContent, + endContent, + children, + ...restProps + } = props - const { - asChild: childrenContainerAsChild, - className: childrenContainerClassName, - ...restChildrenContainerProps - } = getOptionalObject(childrenContainerProps); + const { + asChild: childrenContainerAsChild, + className: childrenContainerClassName, + ...restChildrenContainerProps + } = getOptionalObject(childrenContainerProps) - const ContentComponent = polymorphic(asChild, "div"); + const ContentComponent = polymorphic(asChild, 'div') - const ChildrenContainerComponent = polymorphic( - childrenContainerAsChild, - "span" - ); + const ChildrenContainerComponent = polymorphic(childrenContainerAsChild, 'span') - return ( - - {startContent} - - {children} - - {endContent} - - ); -}; + return ( + + {startContent} + + {children} + + {endContent} + + ) +} -export { CardHeader }; +export { CardHeader } diff --git a/src/components/card/components/card-title.tsx b/src/components/card/components/card-title.tsx index 7501ca1..8c9d31c 100644 --- a/src/components/card/components/card-title.tsx +++ b/src/components/card/components/card-title.tsx @@ -1,21 +1,21 @@ -import { cx } from "@renderui/utils"; -import React from "react"; +import { cx } from '@renderui/utils' +import React from 'react' -import { DEFAULT_CARD_TITLE_CLASSNAME } from "@/components/card/constants/constants"; -import { CardTitleProps } from "@/components/card/types/card-title"; -import { Text } from "@/components/text"; +import { DEFAULT_CARD_TITLE_CLASSNAME } from '@/components/card/constants/constants' +import { CardTitleProps } from '@/components/card/types/card-title' +import { Text } from '@/components/text' const CardTitle = (props: CardTitleProps) => { - const { className, size = "md", ...restProps } = props; + const { className, size = 'md', ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { CardTitle }; +export { CardTitle } diff --git a/src/components/card/components/card.tsx b/src/components/card/components/card.tsx index f30000e..a2a98d2 100644 --- a/src/components/card/components/card.tsx +++ b/src/components/card/components/card.tsx @@ -1,24 +1,17 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { cardClasses } from "@/components/card/classes/card-classes"; -import { CardProps } from "@/components/card/types/card"; +import { cardClasses } from '@/components/card/classes/card-classes' +import { CardProps } from '@/components/card/types/card' const Card = (props: CardProps) => { - const { asChild, className, isBlurred, hasShadowOnHover, ...restProps } = - props; + const { asChild, className, isBlurred, hasShadowOnHover, ...restProps } = props - const variantClassName = cardClasses({ isBlurred, hasShadowOnHover }); + const variantClassName = cardClasses({ isBlurred, hasShadowOnHover }) - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - ); -}; + return +} -export { Card }; +export { Card } diff --git a/src/components/card/constants/constants.ts b/src/components/card/constants/constants.ts index 22febfe..d855348 100644 --- a/src/components/card/constants/constants.ts +++ b/src/components/card/constants/constants.ts @@ -1,26 +1,26 @@ const DEFAULT_CARD_HEADER_CONTENT_CLASSNAME = - 'render-ui-card-header-content flex items-center gap-4 pt-3 pb-2 px-4' + 'render-ui-card-header-content flex items-center gap-4 pt-3 pb-2 px-4' const DEFAULT_CARD_HEADER_CHILDREN_CLASSNAME = 'render-ui-card-header-children flex grow flex-col' const DEFAULT_CARD_BODY_CLASSNAME = 'render-ui-card-body py-3 px-4 text-sm' const DEFAULT_CARD_FOOTER_CLASSNAME = - 'render-ui-card-footer flex justify-end items-center gap-2 pt-2 pb-3 px-4' + 'render-ui-card-footer flex justify-end items-center gap-2 pt-2 pb-3 px-4' const DEFAULT_CARD_FOOTER_CHILDREN_CLASSNAME = - 'render-ui-card-footer-children flex grow flex-col-reverse gap-2 xs:flex-row xs:justify-end' + 'render-ui-card-footer-children flex grow flex-col-reverse gap-2 xs:flex-row xs:justify-end' const DEFAULT_CARD_TITLE_CLASSNAME = 'render-ui-card-title font-semibold' const DEFAULT_CARD_DESCRIPTION_CLASSNAME = 'render-ui-card-description text-mode-contrast-accent' export { - DEFAULT_CARD_BODY_CLASSNAME, - DEFAULT_CARD_DESCRIPTION_CLASSNAME, - DEFAULT_CARD_FOOTER_CHILDREN_CLASSNAME, - DEFAULT_CARD_FOOTER_CLASSNAME, - DEFAULT_CARD_HEADER_CHILDREN_CLASSNAME, - DEFAULT_CARD_HEADER_CONTENT_CLASSNAME, - DEFAULT_CARD_TITLE_CLASSNAME, + DEFAULT_CARD_BODY_CLASSNAME, + DEFAULT_CARD_DESCRIPTION_CLASSNAME, + DEFAULT_CARD_FOOTER_CHILDREN_CLASSNAME, + DEFAULT_CARD_FOOTER_CLASSNAME, + DEFAULT_CARD_HEADER_CHILDREN_CLASSNAME, + DEFAULT_CARD_HEADER_CONTENT_CLASSNAME, + DEFAULT_CARD_TITLE_CLASSNAME, } diff --git a/src/components/card/types/card-body.ts b/src/components/card/types/card-body.ts index bea2715..44f5368 100644 --- a/src/components/card/types/card-body.ts +++ b/src/components/card/types/card-body.ts @@ -1,8 +1,8 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type CardBodyProps = Simplify & AsChildProp>; +type CardBodyProps = Simplify & AsChildProp> -export type { CardBodyProps, CardBodyRef }; +export type { CardBodyProps, CardBodyRef } diff --git a/src/components/card/types/card-description.ts b/src/components/card/types/card-description.ts index 4ac0e69..e198db6 100644 --- a/src/components/card/types/card-description.ts +++ b/src/components/card/types/card-description.ts @@ -1,5 +1,5 @@ -import { TextProps } from "@/components/text"; +import { TextProps } from '@/components/text' -type CardDescriptionProps = TextProps; +type CardDescriptionProps = TextProps -export type { CardDescriptionProps }; +export type { CardDescriptionProps } diff --git a/src/components/card/types/card-footer.ts b/src/components/card/types/card-footer.ts index 9031834..b54045c 100644 --- a/src/components/card/types/card-footer.ts +++ b/src/components/card/types/card-footer.ts @@ -1,25 +1,18 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type CardFooterPrimitiveProps = Omit< - React.ComponentPropsWithRef<"div">, - "className" ->; +type CardFooterPrimitiveProps = Omit, 'className'> type CardFooterCustomProps = { - startContent?: React.ReactNode; - endContent?: React.ReactNode; - childrenClassName?: string; - contentClassName?: string; - childrenContainerProps?: Simplify< - React.ComponentPropsWithRef<"span"> & AsChildProp - >; -}; + startContent?: React.ReactNode + endContent?: React.ReactNode + childrenClassName?: string + contentClassName?: string + childrenContainerProps?: Simplify & AsChildProp> +} -type CardFooterProps = Simplify< - CardFooterPrimitiveProps & CardFooterCustomProps & AsChildProp ->; +type CardFooterProps = Simplify -export type { CardFooterProps }; +export type { CardFooterProps } diff --git a/src/components/card/types/card-header.ts b/src/components/card/types/card-header.ts index cb2aa1e..2e15c13 100644 --- a/src/components/card/types/card-header.ts +++ b/src/components/card/types/card-header.ts @@ -1,25 +1,18 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type CardHeaderPrimitiveProps = Omit< - React.ComponentPropsWithRef<"div">, - "className" ->; +type CardHeaderPrimitiveProps = Omit, 'className'> type CardHeaderCustomProps = { - startContent?: React.ReactNode; - endContent?: React.ReactNode; - childrenClassName?: string; - contentClassName?: string; - childrenContainerProps?: Simplify< - React.ComponentPropsWithRef<"span"> & AsChildProp - >; -}; + startContent?: React.ReactNode + endContent?: React.ReactNode + childrenClassName?: string + contentClassName?: string + childrenContainerProps?: Simplify & AsChildProp> +} -type CardHeaderProps = Simplify< - CardHeaderPrimitiveProps & CardHeaderCustomProps & AsChildProp ->; +type CardHeaderProps = Simplify -export type { CardHeaderProps }; +export type { CardHeaderProps } diff --git a/src/components/card/types/card-title.ts b/src/components/card/types/card-title.ts index 5c00b92..d5c0c03 100644 --- a/src/components/card/types/card-title.ts +++ b/src/components/card/types/card-title.ts @@ -1,5 +1,5 @@ -import { TextProps } from "@/components/text"; +import { TextProps } from '@/components/text' -type CardTitleProps = TextProps; +type CardTitleProps = TextProps -export type { CardTitleProps }; +export type { CardTitleProps } diff --git a/src/components/card/types/card.ts b/src/components/card/types/card.ts index e9e68bd..89cd18d 100644 --- a/src/components/card/types/card.ts +++ b/src/components/card/types/card.ts @@ -1,14 +1,14 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { cardClasses } from "@/components/card/classes/card-classes"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { cardClasses } from '@/components/card/classes/card-classes' -type CardPrimitiveProps = React.ComponentPropsWithRef<"div">; +type CardPrimitiveProps = React.ComponentPropsWithRef<'div'> -type CardVariantProps = NonNullableVariantProps; +type CardVariantProps = NonNullableVariantProps -type CardProps = Simplify; +type CardProps = Simplify -export type { CardProps }; +export type { CardProps } diff --git a/src/components/checkbox/components/checkbox-indicator.tsx b/src/components/checkbox/components/checkbox-indicator.tsx index ce89d80..4a590ca 100644 --- a/src/components/checkbox/components/checkbox-indicator.tsx +++ b/src/components/checkbox/components/checkbox-indicator.tsx @@ -4,63 +4,63 @@ import React from 'react' import { DEFAULT_CHECKBOX_INDICATOR_CLASSNAME } from '@/components/checkbox/constants/constants' import { - CheckboxIndicatorProps, - CheckboxIndicatorRef, + CheckboxIndicatorProps, + CheckboxIndicatorRef, } from '@/components/checkbox/types/checkbox-indicator' import { getMergedIndicatorVariantAnimation } from '@/components/checkbox/utils/get-merged-indicator-variant-animation' import { LazyMotionDomAnimationProvider } from '@/providers' const CheckboxIndicator = React.forwardRef( - (props, ref) => { - const { - isChecked, - hasIconContentWhenUnchecked, - className, - pathProps, - animate, - animationDuration, - initial = false, - fill = 'none', - viewBox = '0 0 24 24', - ...restProps - } = props + (props, ref) => { + const { + isChecked, + hasIconContentWhenUnchecked, + className, + pathProps, + animate, + animationDuration, + initial = false, + fill = 'none', + viewBox = '0 0 24 24', + ...restProps + } = props - const { - strokeLinecap = 'round', - strokeLinejoin = 'round', - d: dProp = 'M4.5 12.75l6 6 9-13.5', - variants, - ...restPathprops - } = getOptionalObject(pathProps) + const { + strokeLinecap = 'round', + strokeLinejoin = 'round', + d: dProp = 'M4.5 12.75l6 6 9-13.5', + variants, + ...restPathprops + } = getOptionalObject(pathProps) - return ( - - - - - - ) - }, + return ( + + + + + + ) + }, ) CheckboxIndicator.displayName = 'CheckboxIndicator' diff --git a/src/components/checkbox/components/checkbox.tsx b/src/components/checkbox/components/checkbox.tsx index 4eec13b..6fc08a0 100644 --- a/src/components/checkbox/components/checkbox.tsx +++ b/src/components/checkbox/components/checkbox.tsx @@ -1,121 +1,107 @@ -"use client"; +'use client' -import { - chain, - cn, - cx, - functionCallOrValue, - getOptionalObject, - polymorphic, -} from "@renderui/utils"; -import React from "react"; +import { chain, cn, cx, functionCallOrValue, getOptionalObject, polymorphic } from '@renderui/utils' +import React from 'react' -import { Button } from "@/components/button"; -import { CheckboxIndicator } from "@/components/checkbox/components/checkbox-indicator"; +import { Button } from '@/components/button' +import { CheckboxIndicator } from '@/components/checkbox/components/checkbox-indicator' import { - DEFAULT_CHECKBOX_CLASSNAME, - DEFAULT_CHECKBOX_HIDDEN_INPUT_CLASSNAME, -} from "@/components/checkbox/constants/constants"; -import { CheckboxProps } from "@/components/checkbox/types/checkbox"; -import { VisuallyHidden } from "@/components/visually-hidden"; -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; + DEFAULT_CHECKBOX_CLASSNAME, + DEFAULT_CHECKBOX_HIDDEN_INPUT_CLASSNAME, +} from '@/components/checkbox/constants/constants' +import { CheckboxProps } from '@/components/checkbox/types/checkbox' +import { VisuallyHidden } from '@/components/visually-hidden' +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' const Checkbox = (props: CheckboxProps) => { - const { - inputRef, - inputProps, - name, - className, - defaultChecked, - isChecked: checkedProp, - isDisabled, - isInvalid, - isReadOnly, - isRequired, - startContent, - endContent, - children, - animationDuration, - onCheckedChange, - onPress, - color = "primary", - hasRipple = false, - hasIconContentWhenUnchecked = true, - ...restProps - } = props; + const { + inputRef, + inputProps, + name, + className, + defaultChecked, + isChecked: checkedProp, + isDisabled, + isInvalid, + isReadOnly, + isRequired, + startContent, + endContent, + children, + animationDuration, + onCheckedChange, + onPress, + color = 'primary', + hasRipple = false, + hasIconContentWhenUnchecked = true, + ...restProps + } = props - const [checked, setChecked] = useControllableState({ - prop: checkedProp, - defaultProp: defaultChecked, - onChange: onCheckedChange, - }); + const [checked, setChecked] = useControllableState({ + prop: checkedProp, + defaultProp: defaultChecked, + onChange: onCheckedChange, + }) - const { - asChild, - name: inputName, - value: inputValue, - className: inputClassName, - checked: inputChecked, - onChange, - tabIndex = -1, - ...restInputProps - } = getOptionalObject(inputProps); + const { + asChild, + name: inputName, + value: inputValue, + className: inputClassName, + checked: inputChecked, + onChange, + tabIndex = -1, + ...restInputProps + } = getOptionalObject(inputProps) - const InputComponent = polymorphic(asChild, "input"); + const InputComponent = polymorphic(asChild, 'input') - return ( - - ); -}; + return ( + + ) +} -export { Checkbox }; +export { Checkbox } diff --git a/src/components/checkbox/constants/constants.ts b/src/components/checkbox/constants/constants.ts index a308d79..78327a5 100644 --- a/src/components/checkbox/constants/constants.ts +++ b/src/components/checkbox/constants/constants.ts @@ -1,28 +1,28 @@ const DEFAULT_CHECKBOX_CLASSNAME = - 'render-ui-checkbox p-0.5 bg-transparent rounded-md min-w-0 h-fit w-fit aspect-square shrink-0 text-white data-[state=checked]:bg-primary data-[invalid=true]:ring-destructive' + 'render-ui-checkbox p-0.5 bg-transparent rounded-md min-w-0 h-fit w-fit aspect-square shrink-0 text-white data-[state=checked]:bg-primary data-[invalid=true]:ring-destructive' const DEFAULT_CHECKBOX_INDICATOR_CLASSNAME = - 'render-ui-checkbox-indicator h-[0.85rem] w-[0.85rem] stroke-white stroke-[2.5]' + 'render-ui-checkbox-indicator h-[0.85rem] w-[0.85rem] stroke-white stroke-[2.5]' const DEFAULT_CHECKBOX_HIDDEN_INPUT_CLASSNAME = 'render-ui-checkbox-hidden-input' const DEFEAULT_MOTION_PROPS = { - checked: { - pathLength: 1, - opacity: 1, - transition: { - duration: 0.275, - delay: 0, - }, - }, - unchecked: { - pathLength: 0, - opacity: 0, - transition: { - duration: 0, - delay: 0, - }, - }, + checked: { + pathLength: 1, + opacity: 1, + transition: { + duration: 0.275, + delay: 0, + }, + }, + unchecked: { + pathLength: 0, + opacity: 0, + transition: { + duration: 0, + delay: 0, + }, + }, } as const const CHECKBOX_BUTTON_ROLE_TYPE_CONFIG = { role: 'checkbox', type: 'button' } as const @@ -30,10 +30,10 @@ const CHECKBOX_BUTTON_ROLE_TYPE_CONFIG = { role: 'checkbox', type: 'button' } as const CHECKBOX_INPUT_TYPE_CONFIG = { type: 'checkbox' } as const export { - CHECKBOX_BUTTON_ROLE_TYPE_CONFIG, - CHECKBOX_INPUT_TYPE_CONFIG, - DEFAULT_CHECKBOX_CLASSNAME, - DEFAULT_CHECKBOX_HIDDEN_INPUT_CLASSNAME, - DEFAULT_CHECKBOX_INDICATOR_CLASSNAME, - DEFEAULT_MOTION_PROPS, + CHECKBOX_BUTTON_ROLE_TYPE_CONFIG, + CHECKBOX_INPUT_TYPE_CONFIG, + DEFAULT_CHECKBOX_CLASSNAME, + DEFAULT_CHECKBOX_HIDDEN_INPUT_CLASSNAME, + DEFAULT_CHECKBOX_INDICATOR_CLASSNAME, + DEFEAULT_MOTION_PROPS, } diff --git a/src/components/checkbox/types/checkbox-indicator.ts b/src/components/checkbox/types/checkbox-indicator.ts index 02ec42a..e9bf085 100644 --- a/src/components/checkbox/types/checkbox-indicator.ts +++ b/src/components/checkbox/types/checkbox-indicator.ts @@ -1,22 +1,22 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import { m } from "framer-motion"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import { m } from 'framer-motion' +import React from 'react' // type CheckboxIndicatorPrimitive = typeof m.svg; // @TODO // type CheckboxIndicatorPrimitiveProps = React.ComponentPropsWithRef -type CheckboxIndicatorPrimitiveProps = Record; +type CheckboxIndicatorPrimitiveProps = Record type CheckboxIndicatorCustomProps = { - isChecked?: boolean; - animationDuration?: number; - hasIconContentWhenUnchecked?: boolean; - pathProps?: React.ComponentPropsWithRef; -}; + isChecked?: boolean + animationDuration?: number + hasIconContentWhenUnchecked?: boolean + pathProps?: React.ComponentPropsWithRef +} type CheckboxIndicatorProps = Simplify< - CheckboxIndicatorPrimitiveProps & CheckboxIndicatorCustomProps ->; + CheckboxIndicatorPrimitiveProps & CheckboxIndicatorCustomProps +> -export type { CheckboxIndicatorProps }; +export type { CheckboxIndicatorProps } diff --git a/src/components/checkbox/types/checkbox.ts b/src/components/checkbox/types/checkbox.ts index 1ac8e56..d00a337 100644 --- a/src/components/checkbox/types/checkbox.ts +++ b/src/components/checkbox/types/checkbox.ts @@ -1,40 +1,32 @@ -import { Primitive as primitive } from "@radix-ui/react-primitive"; -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Primitive as primitive } from '@radix-ui/react-primitive' +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { ButtonProps } from "@/components/button"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { ButtonProps } from '@/components/button' type CheckboxButtonProps = Omit< - ButtonProps, - | "children" - | "disabled" - | "readonly" - | "required" - | "startContent" - | "children" - | "endContent" ->; + ButtonProps, + 'children' | 'disabled' | 'readonly' | 'required' | 'startContent' | 'children' | 'endContent' +> type CheckboxCustomProps = { - children?: React.ReactNode | ((checked: boolean) => React.ReactNode); - startContent?: React.ReactNode | ((checked: boolean) => React.ReactNode); - endContent?: React.ReactNode | ((checked: boolean) => React.ReactNode); - inputRef?: React.RefObject; - inputProps?: Simplify< - React.ComponentPropsWithRef & AsChildProp - >; - name?: string; - isChecked?: boolean; - isReadOnly?: boolean; - isInvalid?: boolean; - isRequired?: boolean; - defaultChecked?: boolean; - hasIconContentWhenUnchecked?: boolean; - animationDuration?: number; - onCheckedChange?: (isChecked: boolean) => void; -}; + children?: React.ReactNode | ((checked: boolean) => React.ReactNode) + startContent?: React.ReactNode | ((checked: boolean) => React.ReactNode) + endContent?: React.ReactNode | ((checked: boolean) => React.ReactNode) + inputRef?: React.RefObject + inputProps?: Simplify & AsChildProp> + name?: string + isChecked?: boolean + isReadOnly?: boolean + isInvalid?: boolean + isRequired?: boolean + defaultChecked?: boolean + hasIconContentWhenUnchecked?: boolean + animationDuration?: number + onCheckedChange?: (isChecked: boolean) => void +} -type CheckboxProps = Simplify; +type CheckboxProps = Simplify -export type { CheckboxProps }; +export type { CheckboxProps } diff --git a/src/components/checkbox/utils/get-merged-indicator-variant-animation.ts b/src/components/checkbox/utils/get-merged-indicator-variant-animation.ts index fefe6ef..e096845 100644 --- a/src/components/checkbox/utils/get-merged-indicator-variant-animation.ts +++ b/src/components/checkbox/utils/get-merged-indicator-variant-animation.ts @@ -2,26 +2,26 @@ import { CheckboxIndicatorProps } from '@/checkbox' import { DEFEAULT_MOTION_PROPS } from '@/components/checkbox/constants/constants' function getMergedIndicatorVariantAnimation( - variants: CheckboxIndicatorProps['variants'], - animationDuration: number | undefined, + variants: CheckboxIndicatorProps['variants'], + animationDuration: number | undefined, ) { - if (animationDuration === undefined) - return { - ...DEFEAULT_MOTION_PROPS, - ...variants, - } + if (animationDuration === undefined) + return { + ...DEFEAULT_MOTION_PROPS, + ...variants, + } - return { - ...DEFEAULT_MOTION_PROPS, - checked: { - ...DEFEAULT_MOTION_PROPS.checked, - transition: { - ...DEFEAULT_MOTION_PROPS.checked.transition, - duration: Number.parseFloat((animationDuration / 1000).toFixed(2)), - }, - }, - ...variants, - } + return { + ...DEFEAULT_MOTION_PROPS, + checked: { + ...DEFEAULT_MOTION_PROPS.checked, + transition: { + ...DEFEAULT_MOTION_PROPS.checked.transition, + duration: Number.parseFloat((animationDuration / 1000).toFixed(2)), + }, + }, + ...variants, + } } export { getMergedIndicatorVariantAnimation } diff --git a/src/components/collapsible/components/collapsible-content.tsx b/src/components/collapsible/components/collapsible-content.tsx index dc38a41..666c16d 100644 --- a/src/components/collapsible/components/collapsible-content.tsx +++ b/src/components/collapsible/components/collapsible-content.tsx @@ -5,66 +5,66 @@ import { cn } from '@renderui/utils' import React, { useEffect, useState } from 'react' import { - CollapsibleContentProps, - CollapsibleContentRef, + CollapsibleContentProps, + CollapsibleContentRef, } from '@/components/collapsible/types/collapsible-content' import { - COLLAPSIBLE_ANIMATED_CONTENT_CLASSNAME, - COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION, - DEFAULT_COLLAPSIBLE_CONTENT_CLASSNAME, + COLLAPSIBLE_ANIMATED_CONTENT_CLASSNAME, + COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION, + DEFAULT_COLLAPSIBLE_CONTENT_CLASSNAME, } from '../constants/constants' import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' const CollapsibleContent = React.forwardRef( - (props, ref) => { - const { - style, - className, - hasSkippedInitialAnimation, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - hasDefaultAnimation = true, - ...restProps - } = props + (props, ref) => { + const { + style, + className, + hasSkippedInitialAnimation, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + hasDefaultAnimation = true, + ...restProps + } = props - const [defaultDuration, setDefaultDuration] = useState( - hasSkippedInitialAnimation ? 0 : COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION, - ) + const [defaultDuration, setDefaultDuration] = useState( + hasSkippedInitialAnimation ? 0 : COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION, + ) - useEffect(() => { - setDefaultDuration(COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION) - }, [hasSkippedInitialAnimation]) + useEffect(() => { + setDefaultDuration(COLLAPSIBLE_CONTENT_DEFAULT_ANIMATION_DURATION) + }, [hasSkippedInitialAnimation]) - return ( - - ) - }, + return ( + + ) + }, ) CollapsibleContent.displayName = 'CollapsibleContent' diff --git a/src/components/collapsible/components/collapsible-trigger.tsx b/src/components/collapsible/components/collapsible-trigger.tsx index acf9b39..8288a3d 100644 --- a/src/components/collapsible/components/collapsible-trigger.tsx +++ b/src/components/collapsible/components/collapsible-trigger.tsx @@ -6,27 +6,27 @@ import React from 'react' import { Button } from '@/components/button' import { - CollapsibleTriggerProps, - CollapsibleTriggerRef, + CollapsibleTriggerProps, + CollapsibleTriggerRef, } from '@/components/collapsible/types/collapsible-trigger' const CollapsibleTrigger = React.forwardRef( - (props, ref) => { - const { className, variant = 'solid', color = 'mode-accent' } = props + (props, ref) => { + const { className, variant = 'solid', color = 'mode-accent' } = props - return ( - - - - ) : null} - {children} - - - ); -}; + return ( + + + + {hasCloseButton ? ( + + + + ) : null} + {children} + + + ) +} -export { DialogContent }; +export { DialogContent } diff --git a/src/components/dialog/components/dialog-description.tsx b/src/components/dialog/components/dialog-description.tsx index d36cbb2..1cfd043 100644 --- a/src/components/dialog/components/dialog-description.tsx +++ b/src/components/dialog/components/dialog-description.tsx @@ -1,5 +1,5 @@ -import { ModalDescription } from "@/components/_shared/components/modal-description/modal-description"; +import { ModalDescription } from '@/components/_shared/components/modal-description/modal-description' -const DialogDescription = ModalDescription; +const DialogDescription = ModalDescription -export { DialogDescription }; +export { DialogDescription } diff --git a/src/components/dialog/components/dialog-footer.tsx b/src/components/dialog/components/dialog-footer.tsx index 4098305..f25476f 100644 --- a/src/components/dialog/components/dialog-footer.tsx +++ b/src/components/dialog/components/dialog-footer.tsx @@ -1,5 +1,5 @@ -import { ModalFooter } from "@/components/_shared/components/modal-footer/modal-footer"; +import { ModalFooter } from '@/components/_shared/components/modal-footer/modal-footer' -const DialogFooter = ModalFooter; +const DialogFooter = ModalFooter -export { DialogFooter }; +export { DialogFooter } diff --git a/src/components/dialog/components/dialog-header.tsx b/src/components/dialog/components/dialog-header.tsx index 20639d1..2bcd974 100644 --- a/src/components/dialog/components/dialog-header.tsx +++ b/src/components/dialog/components/dialog-header.tsx @@ -1,5 +1,5 @@ -import { ModalHeader } from "@/components/_shared/components/modal-header/modal-header"; +import { ModalHeader } from '@/components/_shared/components/modal-header/modal-header' -const DialogHeader = ModalHeader; +const DialogHeader = ModalHeader -export { DialogHeader }; +export { DialogHeader } diff --git a/src/components/dialog/components/dialog-trigger.tsx b/src/components/dialog/components/dialog-trigger.tsx index 8114b73..aa9d6d5 100644 --- a/src/components/dialog/components/dialog-trigger.tsx +++ b/src/components/dialog/components/dialog-trigger.tsx @@ -1,32 +1,27 @@ -"use client"; +'use client' -import { DialogTrigger as DialogTriggerPrimitive } from "@radix-ui/react-dialog"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { DialogTrigger as DialogTriggerPrimitive } from '@radix-ui/react-dialog' +import { cn } from '@renderui/utils' +import React from 'react' -import { Button } from "@/components/button/components/button"; -import { DEFAULT_DIALOG_TRIGGER_CLASSNAME } from "@/components/dialog/constants/constants"; -import { DialogTriggerProps } from "@/components/dialog/types/dialog-trigger"; +import { Button } from '@/components/button/components/button' +import { DEFAULT_DIALOG_TRIGGER_CLASSNAME } from '@/components/dialog/constants/constants' +import { DialogTriggerProps } from '@/components/dialog/types/dialog-trigger' const DialogTrigger = (props: DialogTriggerProps) => { - const { - className, - variant = "solid", - color = "mode-accent", - ...restProps - } = props; + const { className, variant = 'solid', color = 'mode-accent', ...restProps } = props - return ( - - - - ); -}; + return ( + + + + ) +} -export { DrawerTrigger }; +export { DrawerTrigger } diff --git a/src/components/drawer/components/drawer.tsx b/src/components/drawer/components/drawer.tsx index 96c39bd..110a642 100644 --- a/src/components/drawer/components/drawer.tsx +++ b/src/components/drawer/components/drawer.tsx @@ -1,16 +1,11 @@ -import { DrawerProps } from "@/components/drawer/types/drawer"; -import { Drawer as DrawerPrimitive } from "vaul"; -import React from "react"; +import { DrawerProps } from '@/components/drawer/types/drawer' +import { Drawer as DrawerPrimitive } from 'vaul' +import React from 'react' const Drawer = (props: DrawerProps) => { - const { shouldScaleBackground = true, ...restProps } = props; + const { shouldScaleBackground = true, ...restProps } = props - return ( - - ); -}; + return +} -export { Drawer }; +export { Drawer } diff --git a/src/components/drawer/index.ts b/src/components/drawer/index.ts index aee182c..3036819 100644 --- a/src/components/drawer/index.ts +++ b/src/components/drawer/index.ts @@ -1,6 +1,6 @@ -export * from "@/components/drawer/components/drawer"; -export * from "@/components/drawer/components/drawer-trigger"; -export * from "@/components/drawer/components/drawer-content"; -export * from "@/components/drawer/types/drawer"; -export * from "@/components/drawer/types/drawer-trigger"; -export * from "@/components/drawer/types/drawer-content"; +export * from '@/components/drawer/components/drawer' +export * from '@/components/drawer/components/drawer-trigger' +export * from '@/components/drawer/components/drawer-content' +export * from '@/components/drawer/types/drawer' +export * from '@/components/drawer/types/drawer-trigger' +export * from '@/components/drawer/types/drawer-content' diff --git a/src/components/drawer/types/drawer-content.ts b/src/components/drawer/types/drawer-content.ts index 1a4f2f9..ee732c6 100644 --- a/src/components/drawer/types/drawer-content.ts +++ b/src/components/drawer/types/drawer-content.ts @@ -1,7 +1,5 @@ -import { Drawer as DrawerPrimitive } from "vaul"; +import { Drawer as DrawerPrimitive } from 'vaul' -type DrawerContentProps = React.ComponentPropsWithRef< - typeof DrawerPrimitive.Content ->; +type DrawerContentProps = React.ComponentPropsWithRef -export type { DrawerContentProps }; +export type { DrawerContentProps } diff --git a/src/components/drawer/types/drawer-trigger.ts b/src/components/drawer/types/drawer-trigger.ts index 167d04a..35e12fe 100644 --- a/src/components/drawer/types/drawer-trigger.ts +++ b/src/components/drawer/types/drawer-trigger.ts @@ -1,5 +1,5 @@ -import { ButtonProps } from "@/components/button"; +import { ButtonProps } from '@/components/button' -type DrawerTriggerProps = ButtonProps; +type DrawerTriggerProps = ButtonProps -export type { DrawerTriggerProps }; +export type { DrawerTriggerProps } diff --git a/src/components/drawer/types/drawer.ts b/src/components/drawer/types/drawer.ts index a9d7958..04729bd 100644 --- a/src/components/drawer/types/drawer.ts +++ b/src/components/drawer/types/drawer.ts @@ -1,5 +1,5 @@ -import { Drawer as DrawerPrimitive } from "vaul"; +import { Drawer as DrawerPrimitive } from 'vaul' -type DrawerProps = React.ComponentPropsWithRef; +type DrawerProps = React.ComponentPropsWithRef -export type { DrawerProps }; +export type { DrawerProps } diff --git a/src/components/flex/components/flex.tsx b/src/components/flex/components/flex.tsx index 2e1012b..2bf42b2 100644 --- a/src/components/flex/components/flex.tsx +++ b/src/components/flex/components/flex.tsx @@ -1,23 +1,19 @@ -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { FlexProps } from "@/components/flex/types/flex"; -import { getMergedClassName } from "@/components/flex/utils/get-merged-class-name"; +import { FlexProps } from '@/components/flex/types/flex' +import { getMergedClassName } from '@/components/flex/utils/get-merged-class-name' const Flex = (props: FlexProps) => { - const { asChild, children, growChildren, center, className, ...restProps } = - props; + const { asChild, children, growChildren, center, className, ...restProps } = props - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - {children} - - ); -}; + return ( + + {children} + + ) +} -export { Flex }; +export { Flex } diff --git a/src/components/flex/types/flex.ts b/src/components/flex/types/flex.ts index b821723..565cb74 100644 --- a/src/components/flex/types/flex.ts +++ b/src/components/flex/types/flex.ts @@ -1,17 +1,15 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type FlexPropsPrimitiveProps = React.ComponentPropsWithRef<"div">; +type FlexPropsPrimitiveProps = React.ComponentPropsWithRef<'div'> type FlexboxCustomProps = { - growChildren?: boolean; - center?: boolean; -}; + growChildren?: boolean + center?: boolean +} -type FlexProps = Simplify< - FlexPropsPrimitiveProps & FlexboxCustomProps & AsChildProp ->; +type FlexProps = Simplify -export type { FlexProps }; +export type { FlexProps } diff --git a/src/components/flex/utils/get-merged-class-name.ts b/src/components/flex/utils/get-merged-class-name.ts index 2e81c22..18cfc32 100644 --- a/src/components/flex/utils/get-merged-class-name.ts +++ b/src/components/flex/utils/get-merged-class-name.ts @@ -3,16 +3,16 @@ import { cn } from '@renderui/utils' import { FlexProps } from '@/components/flex/types/flex' function getMergedClassName( - growChildren: FlexProps['growChildren'], - center: FlexProps['center'], - className: FlexProps['className'], + growChildren: FlexProps['growChildren'], + center: FlexProps['center'], + className: FlexProps['className'], ) { - return cn( - 'render-ui-flex flex', - growChildren ? 'grow-children' : '', - center ? 'center' : '', - className, - ) + return cn( + 'render-ui-flex flex', + growChildren ? 'grow-children' : '', + center ? 'center' : '', + className, + ) } export { getMergedClassName } diff --git a/src/components/form/components/form.tsx b/src/components/form/components/form.tsx index fde5d46..fcdf020 100644 --- a/src/components/form/components/form.tsx +++ b/src/components/form/components/form.tsx @@ -1,32 +1,28 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { FormProps } from "@/components/form/types/form"; -import { getSubmitProps } from "@/components/form/utils/get-submit-props"; +import { FormProps } from '@/components/form/types/form' +import { getSubmitProps } from '@/components/form/utils/get-submit-props' const Form = (props: FormProps) => { - const { - asChild, - className, - onSubmit, - onSubmitWithFields, - isDefaultPreventedOnSubmit = true, - ...restProps - } = props; + const { + asChild, + className, + onSubmit, + onSubmitWithFields, + isDefaultPreventedOnSubmit = true, + ...restProps + } = props - const Component = polymorphic(asChild, "form"); + const Component = polymorphic(asChild, 'form') - return ( - - ); -}; + return ( + + ) +} -export { Form }; +export { Form } diff --git a/src/components/form/types/form.ts b/src/components/form/types/form.ts index 8d43c81..caca4e9 100644 --- a/src/components/form/types/form.ts +++ b/src/components/form/types/form.ts @@ -1,18 +1,15 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import { FormEvent } from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import { FormEvent } from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type FormPrimitiveProps = React.ComponentPropsWithRef<"form">; +type FormPrimitiveProps = React.ComponentPropsWithRef<'form'> type FormRenderUIProps = { - isDefaultPreventedOnSubmit?: boolean; - onSubmitWithFields?: ( - formData?: { [k: string]: FormDataEntryValue }, - event?: FormEvent - ) => void; -}; + isDefaultPreventedOnSubmit?: boolean + onSubmitWithFields?: (formData?: { [k: string]: FormDataEntryValue }, event?: FormEvent) => void +} -type FormProps = Simplify; +type FormProps = Simplify -export type { FormProps }; +export type { FormProps } diff --git a/src/components/form/utils/get-form-data.ts b/src/components/form/utils/get-form-data.ts index 7eda57a..7d424c2 100644 --- a/src/components/form/utils/get-form-data.ts +++ b/src/components/form/utils/get-form-data.ts @@ -1,12 +1,12 @@ function getFormData(event: React.FormEvent) { - const formData = new FormData(event.currentTarget) - const result: { [key: string]: FormDataEntryValue } = {} + const formData = new FormData(event.currentTarget) + const result: { [key: string]: FormDataEntryValue } = {} - formData.forEach((value, key) => { - result[key] = value - }) + formData.forEach((value, key) => { + result[key] = value + }) - return result + return result } export { getFormData } diff --git a/src/components/form/utils/get-submit-props.ts b/src/components/form/utils/get-submit-props.ts index fddc11c..53cb606 100644 --- a/src/components/form/utils/get-submit-props.ts +++ b/src/components/form/utils/get-submit-props.ts @@ -3,21 +3,21 @@ import { getFormData } from '@/components/form/utils/get-form-data' /* we are checking if submit handler is attached, if not return undefined to keep server-component functionality */ const getSubmitProps = ( - isDefaultPreventedOnSubmit: FormProps['isDefaultPreventedOnSubmit'], - onSubmit: FormProps['onSubmit'], - onSubmitWithFields: FormProps['onSubmitWithFields'], + isDefaultPreventedOnSubmit: FormProps['isDefaultPreventedOnSubmit'], + onSubmit: FormProps['onSubmit'], + onSubmitWithFields: FormProps['onSubmitWithFields'], ) => { - if (!onSubmit && !onSubmitWithFields) return undefined + if (!onSubmit && !onSubmitWithFields) return undefined - return { - onSubmit: (event: React.FormEvent) => { - if (isDefaultPreventedOnSubmit) event.preventDefault() + return { + onSubmit: (event: React.FormEvent) => { + if (isDefaultPreventedOnSubmit) event.preventDefault() - if (onSubmit) onSubmit(event) + if (onSubmit) onSubmit(event) - if (onSubmitWithFields) onSubmitWithFields(getFormData(event), event) - }, - } + if (onSubmitWithFields) onSubmitWithFields(getFormData(event), event) + }, + } } export { getSubmitProps } diff --git a/src/components/grid/components/grid.tsx b/src/components/grid/components/grid.tsx index d201e15..2f61aff 100644 --- a/src/components/grid/components/grid.tsx +++ b/src/components/grid/components/grid.tsx @@ -1,26 +1,23 @@ -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { GridProps } from "@/components/grid/types/grid"; -import { getMergedStyles } from "@/components/grid/utils/get-merged-styles"; +import { GridProps } from '@/components/grid/types/grid' +import { getMergedStyles } from '@/components/grid/utils/get-merged-styles' const Grid = (props: GridProps) => { - const { asChild, className, style, cols, autoFit, autoFill, ...restProps } = - props; + const { asChild, className, style, cols, autoFit, autoFill, ...restProps } = props - const { mergedClassName, mergedStyle } = getMergedStyles( - className, - style, - cols, - autoFit, - autoFill - ); + const { mergedClassName, mergedStyle } = getMergedStyles( + className, + style, + cols, + autoFit, + autoFill, + ) - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - return ( - - ); -}; + return +} -export { Grid }; +export { Grid } diff --git a/src/components/grid/types/grid.ts b/src/components/grid/types/grid.ts index c8a7866..c63ab5d 100644 --- a/src/components/grid/types/grid.ts +++ b/src/components/grid/types/grid.ts @@ -1,28 +1,23 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type Without = { [P in Exclude]?: never }; +type Without = { [P in Exclude]?: never } type ExclusiveUnion = T | U extends Record - ? (Without & U) | (Without & T) - : T | U; + ? (Without & U) | (Without & T) + : T | U -type GridPrimitiveProps = React.ComponentPropsWithRef<"div">; +type GridPrimitiveProps = React.ComponentPropsWithRef<'div'> type GridCustomProps = { - cols?: string | number; - autoFit?: number; - autoFill?: number; -}; + cols?: string | number + autoFit?: number + autoFill?: number +} -type GridAutoProps = ExclusiveUnion< - { autoFit?: number }, - { autoFill?: number } ->; +type GridAutoProps = ExclusiveUnion<{ autoFit?: number }, { autoFill?: number }> -type GridProps = Simplify< - GridPrimitiveProps & GridCustomProps & GridAutoProps & AsChildProp ->; +type GridProps = Simplify -export type { GridProps }; +export type { GridProps } diff --git a/src/components/grid/utils/get-merged-styles.ts b/src/components/grid/utils/get-merged-styles.ts index 6fbebbc..b25eadb 100644 --- a/src/components/grid/utils/get-merged-styles.ts +++ b/src/components/grid/utils/get-merged-styles.ts @@ -5,77 +5,77 @@ import React from 'react' import { GridProps } from '@/components/grid/types/grid' const sanitizeCols = (cols: GridProps['cols']) => - Number.isNaN(Number(cols)) - ? String(cols).replaceAll(/\s/g, '_') - : Array.from({ length: Number(cols) }) - .fill('1fr') - .join(' ') + Number.isNaN(Number(cols)) + ? String(cols).replaceAll(/\s/g, '_') + : Array.from({ length: Number(cols) }) + .fill('1fr') + .join(' ') function getColsStyle( - style: GridProps['style'], - cols: GridProps['cols'], - autoFit: GridProps['autoFit'], - autoFill: GridProps['autoFill'], + style: GridProps['style'], + cols: GridProps['cols'], + autoFit: GridProps['autoFit'], + autoFill: GridProps['autoFill'], ) { - if (autoFit) { - return { - ...style, - '--grid-auto-fit': `${autoFit}px`, - } as React.CSSProperties - } + if (autoFit) { + return { + ...style, + '--grid-auto-fit': `${autoFit}px`, + } as React.CSSProperties + } - if (autoFill) { - return { - ...style, - '--grid-auto-fill': `${autoFill}px`, - } as React.CSSProperties - } + if (autoFill) { + return { + ...style, + '--grid-auto-fill': `${autoFill}px`, + } as React.CSSProperties + } - if (cols) { - return { - ...style, - '--grid-cols': sanitizeCols(cols), - } as React.CSSProperties - } + if (cols) { + return { + ...style, + '--grid-cols': sanitizeCols(cols), + } as React.CSSProperties + } - return style + return style } function getColsClassName( - className: GridProps['className'], - cols: GridProps['cols'], - autoFit: GridProps['autoFit'], - autoFill: GridProps['autoFill'], + className: GridProps['className'], + cols: GridProps['cols'], + autoFit: GridProps['autoFit'], + autoFill: GridProps['autoFill'], ) { - if (autoFit) { - return 'grid-cols-[repeat(auto-fit,minmax(min(100%,var(--grid-auto-fit)),1fr))]' - } + if (autoFit) { + return 'grid-cols-[repeat(auto-fit,minmax(min(100%,var(--grid-auto-fit)),1fr))]' + } - if (autoFill) { - return 'grid-cols-[repeat(auto-fill,minmax(min(100%,var(--grid-auto-fill)),1fr))]' - } + if (autoFill) { + return 'grid-cols-[repeat(auto-fill,minmax(min(100%,var(--grid-auto-fill)),1fr))]' + } - if (cols) { - return 'grid-cols-[var(--grid-cols)]' - } + if (cols) { + return 'grid-cols-[var(--grid-cols)]' + } - return className + return className } function getMergedStyles( - className: GridProps['className'], - style: GridProps['style'], - cols: GridProps['cols'], - autoFit: GridProps['autoFit'], - autoFill: GridProps['autoFill'], + className: GridProps['className'], + style: GridProps['style'], + cols: GridProps['cols'], + autoFit: GridProps['autoFit'], + autoFill: GridProps['autoFill'], ) { - const autoClassName = getColsClassName(className, cols, autoFit, autoFill) - const autoStyle = getColsStyle(style, cols, autoFit, autoFill) + const autoClassName = getColsClassName(className, cols, autoFit, autoFill) + const autoStyle = getColsStyle(style, cols, autoFit, autoFill) - return { - mergedClassName: cn('render-ui-grid grid', autoClassName, className), - mergedStyle: autoStyle, - } + return { + mergedClassName: cn('render-ui-grid grid', autoClassName, className), + mergedStyle: autoStyle, + } } export { getMergedStyles } diff --git a/src/components/heading/classes/heading-classes.ts b/src/components/heading/classes/heading-classes.ts index dbca333..d94eb3d 100644 --- a/src/components/heading/classes/heading-classes.ts +++ b/src/components/heading/classes/heading-classes.ts @@ -7,24 +7,24 @@ import { textShadowVariants } from '@/components/_shared/variants/text-shadow' import { textSizeVariants } from '@/components/_shared/variants/text-size' const headingClasses = cva( - 'render-ui-heading box-border text-mode-contrast font-bold tracking-tight', - { - variants: { - as: { - h1: ['text-4xl'], - h2: ['text-3xl'], - h3: ['text-2xl'], - h4: ['text-xl'], - h5: ['text-lg'], - h6: ['text-base'], - }, - size: textSizeVariants, - textBreak: textBreakVariants, - shadow: textShadowVariants, - overflow: textOverflowVariants, - letterSpacing: letterSpacingVariants, - }, - }, + 'render-ui-heading box-border text-mode-contrast font-bold tracking-tight', + { + variants: { + as: { + h1: ['text-4xl'], + h2: ['text-3xl'], + h3: ['text-2xl'], + h4: ['text-xl'], + h5: ['text-lg'], + h6: ['text-base'], + }, + size: textSizeVariants, + textBreak: textBreakVariants, + shadow: textShadowVariants, + overflow: textOverflowVariants, + letterSpacing: letterSpacingVariants, + }, + }, ) export { headingClasses } diff --git a/src/components/heading/components/heading.tsx b/src/components/heading/components/heading.tsx index 7c4602a..72b4986 100644 --- a/src/components/heading/components/heading.tsx +++ b/src/components/heading/components/heading.tsx @@ -1,43 +1,43 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { headingClasses } from "@/components/heading/classes/heading-classes"; -import { HeadingProps } from "@/components/heading/types/heading"; +import { headingClasses } from '@/components/heading/classes/heading-classes' +import { HeadingProps } from '@/components/heading/types/heading' const Heading = (props: HeadingProps) => { - const { - asChild, - children, - className, - size, - overflow, - shadow, - letterSpacing, - textBreak, - as = "h3", - ...restProps - } = props; + const { + asChild, + children, + className, + size, + overflow, + shadow, + letterSpacing, + textBreak, + as = 'h3', + ...restProps + } = props - const Component = polymorphic(asChild, as); + const Component = polymorphic(asChild, as) - return ( - - {children} - - ); -}; + return ( + + {children} + + ) +} -export { Heading }; +export { Heading } diff --git a/src/components/heading/types/heading.ts b/src/components/heading/types/heading.ts index 0e923d8..1d7277f 100644 --- a/src/components/heading/types/heading.ts +++ b/src/components/heading/types/heading.ts @@ -1,20 +1,20 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { headingClasses } from "@/components/heading/classes/heading-classes"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { headingClasses } from '@/components/heading/classes/heading-classes' -type HeadingPrimitiveProps = React.ComponentPropsWithRef<"h1">; +type HeadingPrimitiveProps = React.ComponentPropsWithRef<'h1'> type HeadingCustomProps = { - as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; -}; + as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' +} -type HeadingVariantProps = NonNullableVariantProps; +type HeadingVariantProps = NonNullableVariantProps type HeadingProps = Simplify< - HeadingPrimitiveProps & HeadingCustomProps & HeadingVariantProps & AsChildProp ->; + HeadingPrimitiveProps & HeadingCustomProps & HeadingVariantProps & AsChildProp +> -export type { HeadingProps }; +export type { HeadingProps } diff --git a/src/components/index.ts b/src/components/index.ts index 2bd904d..bc46f2d 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,50 +1,50 @@ -export * from "@/components/accordion"; -export * from "@/components/aria"; -export * from "@/components/aspect-ratio"; -export * from "@/components/box"; -export * from "@/components/button"; -export * from "@/components/card"; -export * from "@/components/checkbox"; -export * from "@/components/combobox"; -export * from "@/components/command"; -export * from "@/components/container"; -export * from "@/components/dialog"; -export * from "@/components/flex"; -export * from "@/components/form"; -export * from "@/components/grid"; -export * from "@/components/heading"; -export * from "@/components/collapsible"; +export * from '@/components/accordion' +export * from '@/components/aria' +export * from '@/components/aspect-ratio' +export * from '@/components/box' +export * from '@/components/button' +export * from '@/components/card' +export * from '@/components/checkbox' +export * from '@/components/combobox' +export * from '@/components/command' +export * from '@/components/container' +export * from '@/components/dialog' +export * from '@/components/flex' +export * from '@/components/form' +export * from '@/components/grid' +export * from '@/components/heading' +export * from '@/components/collapsible' // export * from '@/components/kbd' -export * from "@/components/label"; -export * from "@/components/link"; -export * from "@/components/loader"; -export * from "@/components/navigation-menu"; -export * from "@/components/number-input"; -export * from "@/components/overlay"; -export * from "@/components/popover"; -export * from "@/components/portal"; -export * from "@/components/progress"; -export * from "@/components/radio-group"; -export * from "@/components/ripple"; -export * from "@/components/scroll-area"; -export * from "@/components/select"; -export * from "@/components/separator"; -export * from "@/components/sheet"; -export * from "@/components/skeleton"; -export * from "@/components/slot"; -export * from "@/components/slider"; -export * from "@/components/sub-layer"; -export * from "@/components/switch"; -export * from "@/components/tabs"; -export * from "@/components/text"; -export * from "@/components/text-area"; -export * from "@/components/text-input"; -export * from "@/components/toast"; -export * from "@/components/toast"; -export * from "@/components/toggle"; -export * from "@/components/toggle-group"; -export * from "@/components/toggle-group"; -export * from "@/components/tooltip"; -export * from "@/components/visually-hidden"; -export * from "@/components/segment"; -export * from "@/components/drawer"; +export * from '@/components/label' +export * from '@/components/link' +export * from '@/components/loader' +export * from '@/components/navigation-menu' +export * from '@/components/number-input' +export * from '@/components/overlay' +export * from '@/components/popover' +export * from '@/components/portal' +export * from '@/components/progress' +export * from '@/components/radio-group' +export * from '@/components/ripple' +export * from '@/components/scroll-area' +export * from '@/components/select' +export * from '@/components/separator' +export * from '@/components/sheet' +export * from '@/components/skeleton' +export * from '@/components/slot' +export * from '@/components/slider' +export * from '@/components/sub-layer' +export * from '@/components/switch' +export * from '@/components/tabs' +export * from '@/components/text' +export * from '@/components/text-area' +export * from '@/components/text-input' +export * from '@/components/toast' +export * from '@/components/toast' +export * from '@/components/toggle' +export * from '@/components/toggle-group' +export * from '@/components/toggle-group' +export * from '@/components/tooltip' +export * from '@/components/visually-hidden' +export * from '@/components/segment' +export * from '@/components/drawer' diff --git a/src/components/kbd/components/kbd.tsx b/src/components/kbd/components/kbd.tsx index 1de60e0..1ddf3c8 100644 --- a/src/components/kbd/components/kbd.tsx +++ b/src/components/kbd/components/kbd.tsx @@ -1,39 +1,39 @@ -"use client"; +'use client' -import { cn } from "@renderui/utils/cn"; -import { polymorphic } from "@renderui/utils/polymorphic"; -import React from "react"; +import { cn } from '@renderui/utils/cn' +import { polymorphic } from '@renderui/utils/polymorphic' +import React from 'react' -import { useKeyboardHotkey } from "@/components/_shared/hooks/use-keyboard-hotkey"; -import { DEFAULT_KBD_CLASSNAME } from "@/components/kbd/constants/constants"; -import { KbdProps } from "@/components/kbd/types/kbd"; +import { useKeyboardHotkey } from '@/components/_shared/hooks/use-keyboard-hotkey' +import { DEFAULT_KBD_CLASSNAME } from '@/components/kbd/constants/constants' +import { KbdProps } from '@/components/kbd/types/kbd' const Kbd = (props: KbdProps) => { - const { - asChild, - children, - className, - keyCombination, - keyCombinationOptions, - onKeyCombinationMatch, - isKeyCombinationCasingIgnored = true, - ...restProps - } = props; + const { + asChild, + children, + className, + keyCombination, + keyCombinationOptions, + onKeyCombinationMatch, + isKeyCombinationCasingIgnored = true, + ...restProps + } = props - useKeyboardHotkey({ - keyCombination, - keyCombinationOptions, - onKeyCombinationMatch, - isKeyCombinationCasingIgnored, - }); + useKeyboardHotkey({ + keyCombination, + keyCombinationOptions, + onKeyCombinationMatch, + isKeyCombinationCasingIgnored, + }) - const Component = polymorphic(asChild, "kbd"); + const Component = polymorphic(asChild, 'kbd') - return ( - - {children} - - ); -}; + return ( + + {children} + + ) +} -export { Kbd }; +export { Kbd } diff --git a/src/components/kbd/constants/constants.ts b/src/components/kbd/constants/constants.ts index fbae92b..7f74bbf 100644 --- a/src/components/kbd/constants/constants.ts +++ b/src/components/kbd/constants/constants.ts @@ -1,9 +1,9 @@ const DEFAULT_HOTKEY_OPTIONS = { - preventDefault: true, + preventDefault: true, } as const const DEFAULT_KBD_CLASSNAME = - 'render-ui-kbd flex justify-center items-center gap-1 text-xs text-mode-contrast bg-mode-accent font-[unset] font-medium rounded-md px-2 py-1.5 duration-fast transition-[background-color,box-shadow] shadow-[inset_0_-0.05em_0.5em_#00005506,inset_0_0.05em_hsla(0,0%,100%,0.95),inset_0_0.25em_0.5em_#00005506,inset_0_-0.05em_#00002f26,0_0_0_0.05em_#0009321f,0_0.08em_0.17em_#00062e32] dark:shadow-[inset_0_-0.05em_0.5em_#ddeaf814,inset_0_0.05em_#f1f7feb5,inset_0_0.25em_0.5em_#d8f4f609,inset_0_-0.1em_rgba(0,0,0,0.9),0_0_0_0.075em_#d9edff40,0_0.08em_0.17em_rgba(0,0,0,0.95)]' + 'render-ui-kbd flex justify-center items-center gap-1 text-xs text-mode-contrast bg-mode-accent font-[unset] font-medium rounded-md px-2 py-1.5 duration-fast transition-[background-color,box-shadow] shadow-[inset_0_-0.05em_0.5em_#00005506,inset_0_0.05em_hsla(0,0%,100%,0.95),inset_0_0.25em_0.5em_#00005506,inset_0_-0.05em_#00002f26,0_0_0_0.05em_#0009321f,0_0.08em_0.17em_#00062e32] dark:shadow-[inset_0_-0.05em_0.5em_#ddeaf814,inset_0_0.05em_#f1f7feb5,inset_0_0.25em_0.5em_#d8f4f609,inset_0_-0.1em_rgba(0,0,0,0.9),0_0_0_0.075em_#d9edff40,0_0.08em_0.17em_rgba(0,0,0,0.95)]' const DEFAULT_KBD_ICON_CLASSNAME = 'block h-4 w-4 fill-none stroke-current stroke-[1px]' diff --git a/src/components/kbd/types/kbd.ts b/src/components/kbd/types/kbd.ts index 2c34366..d91fa89 100644 --- a/src/components/kbd/types/kbd.ts +++ b/src/components/kbd/types/kbd.ts @@ -1,24 +1,20 @@ -import { useKeyboardHotkey } from "@/components/_shared/hooks/use-keyboard-hotkey"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { useKeyboardHotkey } from '@/components/_shared/hooks/use-keyboard-hotkey' +import { Simplify } from '@/components/_shared/types/simplify' -type KbdHTMLProps = React.ComponentPropsWithRef<"kbd">; +type KbdHTMLProps = React.ComponentPropsWithRef<'kbd'> type KbdRenderUIProps = { - asChild?: boolean; - hasIcon?: boolean; - iconPosition?: "start" | "end"; - keyCombination?: Parameters[0]["keyCombination"]; - keyCombinationOptions?: Parameters< - typeof useKeyboardHotkey - >[0]["keyCombinationOptions"]; - isKeyCombinationCasingIgnored?: Parameters< - typeof useKeyboardHotkey - >[0]["isKeyCombinationCasingIgnored"]; - onKeyCombinationMatch?: Parameters< - typeof useKeyboardHotkey - >[0]["onKeyCombinationMatch"]; -}; + asChild?: boolean + hasIcon?: boolean + iconPosition?: 'start' | 'end' + keyCombination?: Parameters[0]['keyCombination'] + keyCombinationOptions?: Parameters[0]['keyCombinationOptions'] + isKeyCombinationCasingIgnored?: Parameters< + typeof useKeyboardHotkey + >[0]['isKeyCombinationCasingIgnored'] + onKeyCombinationMatch?: Parameters[0]['onKeyCombinationMatch'] +} -type KbdProps = Simplify; +type KbdProps = Simplify -export type { KbdProps }; +export type { KbdProps } diff --git a/src/components/label/components/label.tsx b/src/components/label/components/label.tsx index 8343cf5..7c1e773 100644 --- a/src/components/label/components/label.tsx +++ b/src/components/label/components/label.tsx @@ -1,24 +1,24 @@ -"use client"; +'use client' -import { chain, cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { chain, cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { DEFAULT_LABEL_CLASSNAME } from "@/components/label/constants/constants"; -import { LabelProps } from "@/components/label/types/label"; -import { handlePreventDoubleClickTextSelection } from "@/components/label/utils/handle-prevent-double-click-text-selection"; +import { DEFAULT_LABEL_CLASSNAME } from '@/components/label/constants/constants' +import { LabelProps } from '@/components/label/types/label' +import { handlePreventDoubleClickTextSelection } from '@/components/label/utils/handle-prevent-double-click-text-selection' const Label = (props: LabelProps) => { - const { asChild, className, onMouseDown, ...restProps } = props; + const { asChild, className, onMouseDown, ...restProps } = props - const Component = polymorphic(asChild, "label"); + const Component = polymorphic(asChild, 'label') - return ( - - ); -}; + return ( + + ) +} -export { Label }; +export { Label } diff --git a/src/components/label/types/label.ts b/src/components/label/types/label.ts index 24934bf..754269b 100644 --- a/src/components/label/types/label.ts +++ b/src/components/label/types/label.ts @@ -1,7 +1,7 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type LabelProps = Simplify & AsChildProp>; +type LabelProps = Simplify & AsChildProp> -export type { LabelProps }; +export type { LabelProps } diff --git a/src/components/label/utils/handle-prevent-double-click-text-selection.ts b/src/components/label/utils/handle-prevent-double-click-text-selection.ts index 4c0a520..51524ed 100644 --- a/src/components/label/utils/handle-prevent-double-click-text-selection.ts +++ b/src/components/label/utils/handle-prevent-double-click-text-selection.ts @@ -1,7 +1,7 @@ function handlePreventDoubleClickTextSelection( - event: React.MouseEvent, + event: React.MouseEvent, ) { - if (!event.defaultPrevented && event.detail > 1) event.preventDefault() + if (!event.defaultPrevented && event.detail > 1) event.preventDefault() } export { handlePreventDoubleClickTextSelection } diff --git a/src/components/link/classes/link-classes.ts b/src/components/link/classes/link-classes.ts index 70cf2a2..e3376e1 100644 --- a/src/components/link/classes/link-classes.ts +++ b/src/components/link/classes/link-classes.ts @@ -2,25 +2,25 @@ import { cn } from '@renderui/utils' import { cva } from 'class-variance-authority' const linkClassVariants = cva( - 'render-ui-link tap-highlight-transparent appearence-none m-0 box-border inline-flex cursor-pointer items-center bg-transparent p-0 text-base text-primary underline-offset-2 outline-none ring-ring-color ring-offset-background transition-[color,box-shadow] duration-fast focus-visible:ring-[2px] focus-visible:ring-offset-offset active:text-primary/80', - { - variants: { - underline: { - 'none': '', - 'hover': 'hover:underline', - 'active': 'active:underline', - 'focus': 'focus:underline', - 'focus-visible': 'focus-visible:underline', - }, - }, - defaultVariants: { - underline: 'hover', - }, - }, + 'render-ui-link tap-highlight-transparent appearence-none m-0 box-border inline-flex cursor-pointer items-center bg-transparent p-0 text-base text-primary underline-offset-2 outline-none ring-ring-color ring-offset-background transition-[color,box-shadow] duration-fast focus-visible:ring-[2px] focus-visible:ring-offset-offset active:text-primary/80', + { + variants: { + underline: { + 'none': '', + 'hover': 'hover:underline', + 'active': 'active:underline', + 'focus': 'focus:underline', + 'focus-visible': 'focus-visible:underline', + }, + }, + defaultVariants: { + underline: 'hover', + }, + }, ) const linkClasses = (props: Parameters[0]) => { - return cn(linkClassVariants({ underline: props?.underline }), props?.class, props?.className) + return cn(linkClassVariants({ underline: props?.underline }), props?.class, props?.className) } export { linkClasses } diff --git a/src/components/loader/classes/loader-classes.ts b/src/components/loader/classes/loader-classes.ts index 64dd9e6..8b7844c 100644 --- a/src/components/loader/classes/loader-classes.ts +++ b/src/components/loader/classes/loader-classes.ts @@ -1,83 +1,83 @@ import { cva } from '@renderui/utils' const loaderClasses = cva(['render-ui-loader box-border inline-block aspect-square'], { - variants: { - isPaused: { - true: '!animate-none', - false: '', - }, - variant: { - base: '', - half: '', - edge: '', - ring: '', - dots: 'top-[1px] flex h-full items-center gap-0.5', - }, - size: { - sm: 'size-4', - md: 'size-5', - lg: 'size-6', - auto: '', - }, - position: { - 'relative': '', - 'absolute-center': '', - 'absolute-start': '', - 'absolute-end': '', - }, - }, - compoundVariants: [ - { - variant: ['base', 'half', 'edge', 'ring', 'dots'], - position: ['absolute-center', 'absolute-start', 'absolute-end'], - className: 'pointer-events-none absolute', - }, - { - position: 'absolute-start', - className: 'left-3', - }, - { - position: 'absolute-end', - className: 'right-3', - }, - { - variant: 'dots', - position: 'relative', - className: 'relative', - }, - { - variant: ['base', 'half', 'ring'], - className: 'border-[2px]', - }, - { - variant: ['edge'], - className: 'border-x-[2px] border-b-[2px]', - }, - { - variant: ['base', 'half', 'edge', 'ring'], - className: 'rounded-full', - }, - { - variant: 'base', - className: 'border-x-current border-b-current border-t-transparent', - }, - { - variant: 'edge', - className: 'border-y-transparent border-l-transparent border-r-current', - }, - { - variant: 'half', - className: 'border-b-transparent border-l-current border-r-transparent border-t-current', - }, - { - variant: ['ring'], - className: 'border-x-mode-accent border-b-mode-accent border-t-current', - }, - { - variant: ['base', 'half', 'edge', 'ring'], - className: 'animate-[spin_700ms_linear_infinite]', - }, - ], + variants: { + isPaused: { + true: '!animate-none', + false: '', + }, + variant: { + base: '', + half: '', + edge: '', + ring: '', + dots: 'top-[1px] flex h-full items-center gap-0.5', + }, + size: { + sm: 'size-4', + md: 'size-5', + lg: 'size-6', + auto: '', + }, + position: { + 'relative': '', + 'absolute-center': '', + 'absolute-start': '', + 'absolute-end': '', + }, + }, + compoundVariants: [ + { + variant: ['base', 'half', 'edge', 'ring', 'dots'], + position: ['absolute-center', 'absolute-start', 'absolute-end'], + className: 'pointer-events-none absolute', + }, + { + position: 'absolute-start', + className: 'left-3', + }, + { + position: 'absolute-end', + className: 'right-3', + }, + { + variant: 'dots', + position: 'relative', + className: 'relative', + }, + { + variant: ['base', 'half', 'ring'], + className: 'border-[2px]', + }, + { + variant: ['edge'], + className: 'border-x-[2px] border-b-[2px]', + }, + { + variant: ['base', 'half', 'edge', 'ring'], + className: 'rounded-full', + }, + { + variant: 'base', + className: 'border-x-current border-b-current border-t-transparent', + }, + { + variant: 'edge', + className: 'border-y-transparent border-l-transparent border-r-current', + }, + { + variant: 'half', + className: 'border-b-transparent border-l-current border-r-transparent border-t-current', + }, + { + variant: ['ring'], + className: 'border-x-mode-accent border-b-mode-accent border-t-current', + }, + { + variant: ['base', 'half', 'edge', 'ring'], + className: 'animate-[spin_700ms_linear_infinite]', + }, + ], }) export { loaderClasses } diff --git a/src/components/loader/components/loader-dot.tsx b/src/components/loader/components/loader-dot.tsx index d15936c..5a65b37 100644 --- a/src/components/loader/components/loader-dot.tsx +++ b/src/components/loader/components/loader-dot.tsx @@ -2,43 +2,43 @@ import { cn } from '@renderui/utils' import React from 'react' import { - DEFAULT_LOADER_DOT_CLASSNAME, - LOADER_DOT_PAUSED_CLASSNAME, + DEFAULT_LOADER_DOT_CLASSNAME, + LOADER_DOT_PAUSED_CLASSNAME, } from '@/components/loader/constants/constants' import { LoaderDotProps } from '@/components/loader/types/loader-dot' const LoaderDot = (props: LoaderDotProps) => { - const { isPaused, className, style, element } = props + const { isPaused, className, style, element } = props - const getMergedStyle = () => { - if (element === 'middle') { - return { - animationDelay: '200ms', - ...style, - } - } + const getMergedStyle = () => { + if (element === 'middle') { + return { + animationDelay: '200ms', + ...style, + } + } - if (element === 'end') { - return { - animationDelay: '400ms', - ...style, - } - } + if (element === 'end') { + return { + animationDelay: '400ms', + ...style, + } + } - return style - } + return style + } - return ( - - ) + return ( + + ) } export { LoaderDot } diff --git a/src/components/loader/components/loader.tsx b/src/components/loader/components/loader.tsx index b72bc44..a6e6dd9 100644 --- a/src/components/loader/components/loader.tsx +++ b/src/components/loader/components/loader.tsx @@ -1,47 +1,47 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { loaderClasses } from "@/components/loader/classes/loader-classes"; -import { LoaderDot } from "@/components/loader/components/loader-dot"; -import { LOADER_DOTS } from "@/components/loader/constants/constants"; -import { LoaderProps } from "@/components/loader/types/loader"; +import { loaderClasses } from '@/components/loader/classes/loader-classes' +import { LoaderDot } from '@/components/loader/components/loader-dot' +import { LOADER_DOTS } from '@/components/loader/constants/constants' +import { LoaderProps } from '@/components/loader/types/loader' const Loader = (props: LoaderProps) => { - const { - asChild, - isPaused, - position = "relative", - variant = "half", - size = "sm", - className, - ...restProps - } = props; + const { + asChild, + isPaused, + position = 'relative', + variant = 'half', + size = 'sm', + className, + ...restProps + } = props - const Component = polymorphic(asChild, "span"); + const Component = polymorphic(asChild, 'span') - return ( - - {Boolean(variant === "dots") && ( - <> - {LOADER_DOTS.map((element) => ( - - ))} - - )} - - ); -}; + return ( + + {Boolean(variant === 'dots') && ( + <> + {LOADER_DOTS.map((element) => ( + + ))} + + )} + + ) +} -export { Loader }; +export { Loader } diff --git a/src/components/loader/constants/constants.ts b/src/components/loader/constants/constants.ts index 62eebe5..ad04841 100644 --- a/src/components/loader/constants/constants.ts +++ b/src/components/loader/constants/constants.ts @@ -1,5 +1,5 @@ const DEFAULT_LOADER_DOT_CLASSNAME = - 'render-ui-loader-dot box-border inline-block size-1 animate-[blink_1400ms_linear_infinite] rounded-full bg-current' + 'render-ui-loader-dot box-border inline-block size-1 animate-[blink_1400ms_linear_infinite] rounded-full bg-current' const LOADER_DOT_PAUSED_CLASSNAME = '!animate-none' diff --git a/src/components/loader/types/loader-dot.ts b/src/components/loader/types/loader-dot.ts index 7a2e71b..570acf3 100644 --- a/src/components/loader/types/loader-dot.ts +++ b/src/components/loader/types/loader-dot.ts @@ -1,12 +1,12 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -type LoaderDotPrimitiveProps = React.ComponentPropsWithRef<"span">; +type LoaderDotPrimitiveProps = React.ComponentPropsWithRef<'span'> type LoaderDotCustomProps = { - isPaused: boolean | undefined; - element?: "start" | "middle" | "end"; -}; + isPaused: boolean | undefined + element?: 'start' | 'middle' | 'end' +} -type LoaderDotProps = Simplify; +type LoaderDotProps = Simplify -export type { LoaderDotProps }; +export type { LoaderDotProps } diff --git a/src/components/loader/types/loader.ts b/src/components/loader/types/loader.ts index 77d998f..5edac17 100644 --- a/src/components/loader/types/loader.ts +++ b/src/components/loader/types/loader.ts @@ -1,15 +1,13 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { loaderClasses } from "@/components/loader/classes/loader-classes"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { loaderClasses } from '@/components/loader/classes/loader-classes' -type LoaderPrimitiveProps = React.ComponentPropsWithRef<"span">; +type LoaderPrimitiveProps = React.ComponentPropsWithRef<'span'> -type LodaerRenderUIProps = NonNullableVariantProps; +type LodaerRenderUIProps = NonNullableVariantProps -type LoaderProps = Simplify< - LoaderPrimitiveProps & LodaerRenderUIProps & AsChildProp ->; +type LoaderProps = Simplify -export type { LoaderProps }; +export type { LoaderProps } diff --git a/src/components/navigation-menu/components/navigation-menu-content.tsx b/src/components/navigation-menu/components/navigation-menu-content.tsx index 5a16c39..dbec8fb 100644 --- a/src/components/navigation-menu/components/navigation-menu-content.tsx +++ b/src/components/navigation-menu/components/navigation-menu-content.tsx @@ -1,45 +1,45 @@ -"use client"; +'use client' -import { NavigationMenuContent as NavigationMenuContentPrimitive } from "@radix-ui/react-navigation-menu"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { NavigationMenuContent as NavigationMenuContentPrimitive } from '@radix-ui/react-navigation-menu' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_NAVIGATION_MENU_CONTENT_CLASSNAME } from "@/components/navigation-menu/constants/constants"; -import { NavigationMenuContentProps } from "@/components/navigation-menu/types/navigation-menu-content"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { DEFAULT_NAVIGATION_MENU_CONTENT_CLASSNAME } from '@/components/navigation-menu/constants/constants' +import { NavigationMenuContentProps } from '@/components/navigation-menu/types/navigation-menu-content' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' const NavigationMenuContent = (props: NavigationMenuContentProps) => { - const { - className, - style, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - ...restProps - } = props; + const { + className, + style, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + ...restProps + } = props - return ( - - ); -}; + return ( + + ) +} -export { NavigationMenuContent }; +export { NavigationMenuContent } diff --git a/src/components/navigation-menu/components/navigation-menu-item.tsx b/src/components/navigation-menu/components/navigation-menu-item.tsx index ab31057..5ee7b4a 100644 --- a/src/components/navigation-menu/components/navigation-menu-item.tsx +++ b/src/components/navigation-menu/components/navigation-menu-item.tsx @@ -1,21 +1,21 @@ -"use client"; +'use client' -import { NavigationMenuItem as NavigationMenuItemPrimitive } from "@radix-ui/react-navigation-menu"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { NavigationMenuItem as NavigationMenuItemPrimitive } from '@radix-ui/react-navigation-menu' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_NAVIGATION_MENU_ITEM_CLASSNAME } from "@/components/navigation-menu/constants/constants"; -import { NavigationMenuItemProps } from "@/components/navigation-menu/types/navigation-menu-item"; +import { DEFAULT_NAVIGATION_MENU_ITEM_CLASSNAME } from '@/components/navigation-menu/constants/constants' +import { NavigationMenuItemProps } from '@/components/navigation-menu/types/navigation-menu-item' const NavigationMenuItem = (props: NavigationMenuItemProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { NavigationMenuItem }; +export { NavigationMenuItem } diff --git a/src/components/navigation-menu/components/navigation-menu-link.tsx b/src/components/navigation-menu/components/navigation-menu-link.tsx index 11fd1ef..0a6fe83 100644 --- a/src/components/navigation-menu/components/navigation-menu-link.tsx +++ b/src/components/navigation-menu/components/navigation-menu-link.tsx @@ -1,31 +1,25 @@ -"use client"; +'use client' -import { NavigationMenuLink as NavigationMenuLinkPrimitive } from "@radix-ui/react-navigation-menu"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { NavigationMenuLink as NavigationMenuLinkPrimitive } from '@radix-ui/react-navigation-menu' +import { cn } from '@renderui/utils' +import React from 'react' -import { Button } from "@/components/button"; -import { DEFAULT_NAVIGATION_MENU_LINK_CLASSNAME } from "@/components/navigation-menu/constants/constants"; -import { NavigationMenuLinkProps } from "@/components/navigation-menu/types/navigation-menu-link"; +import { Button } from '@/components/button' +import { DEFAULT_NAVIGATION_MENU_LINK_CLASSNAME } from '@/components/navigation-menu/constants/constants' +import { NavigationMenuLinkProps } from '@/components/navigation-menu/types/navigation-menu-link' const NavigationMenuLink = (props: NavigationMenuLinkProps) => { - const { - onSelect, - className, - active, - variant = "plain", - ...restProps - } = props; + const { onSelect, className, active, variant = 'plain', ...restProps } = props - return ( - - - - ); -}; + return ( + + + + ) +} -export { NavigationMenuTrigger }; +export { NavigationMenuTrigger } diff --git a/src/components/navigation-menu/components/navigation-menu.tsx b/src/components/navigation-menu/components/navigation-menu.tsx index 2b5e1eb..b97ba91 100644 --- a/src/components/navigation-menu/components/navigation-menu.tsx +++ b/src/components/navigation-menu/components/navigation-menu.tsx @@ -1,130 +1,117 @@ -"use client"; +'use client' import { - NavigationMenuIndicator as NavigationMenuIndicatorPrimitive, - NavigationMenuList as NavigationMenuListPrimitive, - NavigationMenu as NavigationMenuPrimitive, - NavigationMenuViewport as NavigationMenuViewportPrimitive, -} from "@radix-ui/react-navigation-menu"; -import { cn, getOptionalObject } from "@renderui/utils"; -import React from "react"; + NavigationMenuIndicator as NavigationMenuIndicatorPrimitive, + NavigationMenuList as NavigationMenuListPrimitive, + NavigationMenu as NavigationMenuPrimitive, + NavigationMenuViewport as NavigationMenuViewportPrimitive, +} from '@radix-ui/react-navigation-menu' +import { cn, getOptionalObject } from '@renderui/utils' +import React from 'react' import { - DEFAULT_NAVIGATION_MENU_ARROW_CLASSNAME, - DEFAULT_NAVIGATION_MENU_CLASSNAME, - DEFAULT_NAVIGATION_MENU_INDICATOR_CLASSNAME, - DEFAULT_NAVIGATION_MENU_LIST_CLASSNAME, - DEFAULT_NAVIGATION_MENU_VIEWPORT_CLASSNAME, - DEFAULT_NAVIGATION_MENU_VIEWPORT_CONTAINER_CLASSNAME, -} from "@/components/navigation-menu/constants/constants"; -import { NavigationMenuProps } from "@/components/navigation-menu/types/navigation-menu"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; + DEFAULT_NAVIGATION_MENU_ARROW_CLASSNAME, + DEFAULT_NAVIGATION_MENU_CLASSNAME, + DEFAULT_NAVIGATION_MENU_INDICATOR_CLASSNAME, + DEFAULT_NAVIGATION_MENU_LIST_CLASSNAME, + DEFAULT_NAVIGATION_MENU_VIEWPORT_CLASSNAME, + DEFAULT_NAVIGATION_MENU_VIEWPORT_CONTAINER_CLASSNAME, +} from '@/components/navigation-menu/constants/constants' +import { NavigationMenuProps } from '@/components/navigation-menu/types/navigation-menu' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' const NavigationMenu = (props: NavigationMenuProps) => { - const { - className, - children, - viewportProps, - viewportContainerProps, - listProps, - indicatorProps, - indicatorArrowProps, - viewportRef, - viewportContainerRef, - listRef, - indicatorRef, - indicatorArrowRef, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - isFullScreen = false, - hasIndicator = true, - ...restProps - } = props; + const { + className, + children, + viewportProps, + viewportContainerProps, + listProps, + indicatorProps, + indicatorArrowProps, + viewportRef, + viewportContainerRef, + listRef, + indicatorRef, + indicatorArrowRef, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + isFullScreen = false, + hasIndicator = true, + ...restProps + } = props - const { className: indicatorClassName, ...restIndicatorProps } = - getOptionalObject(indicatorProps); - const { className: indicatorArrowClassName, ...restArrowProps } = - getOptionalObject(indicatorArrowProps); - const { className: listClassName, ...restListProps } = - getOptionalObject(listProps); - const { - className: viewportContainerClassName, - ...restViewportContainerProps - } = getOptionalObject(viewportContainerProps); - const { - className: viewportClassName, - style: viewportStyle, - ...restViewportProps - } = getOptionalObject(viewportProps); + const { className: indicatorClassName, ...restIndicatorProps } = getOptionalObject(indicatorProps) + const { className: indicatorArrowClassName, ...restArrowProps } = + getOptionalObject(indicatorArrowProps) + const { className: listClassName, ...restListProps } = getOptionalObject(listProps) + const { className: viewportContainerClassName, ...restViewportContainerProps } = + getOptionalObject(viewportContainerProps) + const { + className: viewportClassName, + style: viewportStyle, + ...restViewportProps + } = getOptionalObject(viewportProps) - return ( - - - {children} - {hasIndicator ? ( - -
- - ) : null} - -
- -
- - ); -}; + return ( + + + {children} + {hasIndicator ? ( + +
+ + ) : null} + +
+ +
+ + ) +} -export { NavigationMenu }; +export { NavigationMenu } diff --git a/src/components/navigation-menu/constants/constants.ts b/src/components/navigation-menu/constants/constants.ts index e5d13c7..e8d35f6 100644 --- a/src/components/navigation-menu/constants/constants.ts +++ b/src/components/navigation-menu/constants/constants.ts @@ -1,44 +1,44 @@ const DEFAULT_NAVIGATION_MENU_CLASSNAME = - 'render-ui-navigation-menu relative z-[1] flex w-fit justify-center' + 'render-ui-navigation-menu relative z-[1] flex w-fit justify-center' const DEFAULT_NAVIGATION_MENU_LIST_CLASSNAME = - 'render-ui-navigation-menu-list m-0 flex list-none justify-center rounded-md p-1' + 'render-ui-navigation-menu-list m-0 flex list-none justify-center rounded-md p-1' const DEFAULT_NAVIGATION_MENU_INDICATOR_CLASSNAME = - 'render-ui-navigation-menu-indicator top-full z-[1] flex h-[10px] items-end justify-center overflow-hidden transition-[width,transform_250ms_ease] data-[state=hidden]:animate-navigation-menu-fade-out data-[state=visible]:animate-navigation-menu-fade-in' + 'render-ui-navigation-menu-indicator top-full z-[1] flex h-[10px] items-end justify-center overflow-hidden transition-[width,transform_250ms_ease] data-[state=hidden]:animate-navigation-menu-fade-out data-[state=visible]:animate-navigation-menu-fade-in' const DEFAULT_NAVIGATION_MENU_ARROW_CLASSNAME = - 'render-ui-navigation-menu-arrow relative top-[70%] h-2.5 w-2.5 rotate-45 rounded-tl-[2px] bg-mode-accent' + 'render-ui-navigation-menu-arrow relative top-[70%] h-2.5 w-2.5 rotate-45 rounded-tl-[2px] bg-mode-accent' const DEFAULT_NAVIGATION_MENU_VIEWPORT_CONTAINER_CLASSNAME = - 'render-ui-navigation-menu-viewport-container absolute z-10 left-0 top-full flex w-fit justify-center perspective-[2000px]' + 'render-ui-navigation-menu-viewport-container absolute z-10 left-0 top-full flex w-fit justify-center perspective-[2000px]' const DEFAULT_NAVIGATION_MENU_VIEWPORT_CLASSNAME = - 'render-ui-navigation-menu-viewport relative z-10 flex-1 mt-2.5 h-[var(--radix-navigation-menu-viewport-height)] w-full origin-[top_center] overflow-hidden rounded-md bg-mode shadow-even-xl [&]:shadow-mode-contrast/20 dark:border-[1px] dark:border-mode-accent [&]:dark:shadow-mode-contrast/[1%] transition-[width,height] duration-medium data-[state=closed]:animate-navigation-menu-scale-out data-[state=open]:animate-navigation-menu-scale-in sm:w-[var(--radix-navigation-menu-viewport-width)]' + 'render-ui-navigation-menu-viewport relative z-10 flex-1 mt-2.5 h-[var(--radix-navigation-menu-viewport-height)] w-full origin-[top_center] overflow-hidden rounded-md bg-mode shadow-even-xl [&]:shadow-mode-contrast/20 dark:border-[1px] dark:border-mode-accent [&]:dark:shadow-mode-contrast/[1%] transition-[width,height] duration-medium data-[state=closed]:animate-navigation-menu-scale-out data-[state=open]:animate-navigation-menu-scale-in sm:w-[var(--radix-navigation-menu-viewport-width)]' const DEFAULT_NAVIGATION_MENU_ITEM_CLASSNAME = 'render-ui-navigation-menu-item' const DEFAULT_NAVIGATION_MENU_TRIGGER_CLASSNAME = - 'render-ui-navigation-menu-trigger group flex select-none gap-0.5 rounded' + 'render-ui-navigation-menu-trigger group flex select-none gap-0.5 rounded' const DEFAULT_NAVIGATION_MENU_TRIGGER_INDICATOR_CLASSNAME = - 'render-ui-navigation-menu-trigger-indicator relative top-px ml-1 h-3 w-3 group-data-[state=open]:rotate-180 transition-transform duration-fast' + 'render-ui-navigation-menu-trigger-indicator relative top-px ml-1 h-3 w-3 group-data-[state=open]:rotate-180 transition-transform duration-fast' const DEFAULT_NAVIGATION_MENU_CONTENT_CLASSNAME = - 'render-ui-navigation-menu-content absolute z-10 left-0 top-0 w-full data-[motion=from-end]:animate-navigation-menu-enter-from-right data-[motion=from-start]:animate-navigation-menu-enter-from-left data-[motion=to-end]:animate-navigation-menu-exit-to-right data-[motion=to-start]:animate-navigation-menu-exit-to-left w-fit h-fit p-4' + 'render-ui-navigation-menu-content absolute z-10 left-0 top-0 w-full data-[motion=from-end]:animate-navigation-menu-enter-from-right data-[motion=from-start]:animate-navigation-menu-enter-from-left data-[motion=to-end]:animate-navigation-menu-exit-to-right data-[motion=to-start]:animate-navigation-menu-exit-to-left w-fit h-fit p-4' const DEFAULT_NAVIGATION_MENU_LINK_CLASSNAME = 'render-ui-navigation-menu-link rounded' export { - DEFAULT_NAVIGATION_MENU_ARROW_CLASSNAME, - DEFAULT_NAVIGATION_MENU_CLASSNAME, - DEFAULT_NAVIGATION_MENU_CONTENT_CLASSNAME, - DEFAULT_NAVIGATION_MENU_INDICATOR_CLASSNAME, - DEFAULT_NAVIGATION_MENU_ITEM_CLASSNAME, - DEFAULT_NAVIGATION_MENU_LINK_CLASSNAME, - DEFAULT_NAVIGATION_MENU_LIST_CLASSNAME, - DEFAULT_NAVIGATION_MENU_TRIGGER_CLASSNAME, - DEFAULT_NAVIGATION_MENU_TRIGGER_INDICATOR_CLASSNAME, - DEFAULT_NAVIGATION_MENU_VIEWPORT_CLASSNAME, - DEFAULT_NAVIGATION_MENU_VIEWPORT_CONTAINER_CLASSNAME, + DEFAULT_NAVIGATION_MENU_ARROW_CLASSNAME, + DEFAULT_NAVIGATION_MENU_CLASSNAME, + DEFAULT_NAVIGATION_MENU_CONTENT_CLASSNAME, + DEFAULT_NAVIGATION_MENU_INDICATOR_CLASSNAME, + DEFAULT_NAVIGATION_MENU_ITEM_CLASSNAME, + DEFAULT_NAVIGATION_MENU_LINK_CLASSNAME, + DEFAULT_NAVIGATION_MENU_LIST_CLASSNAME, + DEFAULT_NAVIGATION_MENU_TRIGGER_CLASSNAME, + DEFAULT_NAVIGATION_MENU_TRIGGER_INDICATOR_CLASSNAME, + DEFAULT_NAVIGATION_MENU_VIEWPORT_CLASSNAME, + DEFAULT_NAVIGATION_MENU_VIEWPORT_CONTAINER_CLASSNAME, } diff --git a/src/components/navigation-menu/index.ts b/src/components/navigation-menu/index.ts index fd28403..f7ab43a 100644 --- a/src/components/navigation-menu/index.ts +++ b/src/components/navigation-menu/index.ts @@ -7,4 +7,4 @@ export * from '@/components/navigation-menu/types/navigation-menu' export * from '@/components/navigation-menu/types/navigation-menu-content' export * from '@/components/navigation-menu/types/navigation-menu-item' export * from '@/components/navigation-menu/types/navigation-menu-link' -export * from '@/components/navigation-menu/types/navigation-menu-trigger' \ No newline at end of file +export * from '@/components/navigation-menu/types/navigation-menu-trigger' diff --git a/src/components/navigation-menu/types/navigation-menu-content.ts b/src/components/navigation-menu/types/navigation-menu-content.ts index 4c69de2..cad9d4c 100644 --- a/src/components/navigation-menu/types/navigation-menu-content.ts +++ b/src/components/navigation-menu/types/navigation-menu-content.ts @@ -1,11 +1,10 @@ -import { NavigationMenuContent as NavigationMenuContentPrimitive } from "@radix-ui/react-navigation-menu"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; -import React from "react"; +import { NavigationMenuContent as NavigationMenuContentPrimitive } from '@radix-ui/react-navigation-menu' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' +import React from 'react' -type NavigationMenuContentPrimitiveType = typeof NavigationMenuContentPrimitive; +type NavigationMenuContentPrimitiveType = typeof NavigationMenuContentPrimitive -type NavigationMenuContentProps = - React.ComponentPropsWithRef & - AnimationStyleVariables; +type NavigationMenuContentProps = React.ComponentPropsWithRef & + AnimationStyleVariables -export type { NavigationMenuContentProps }; +export type { NavigationMenuContentProps } diff --git a/src/components/navigation-menu/types/navigation-menu-item.ts b/src/components/navigation-menu/types/navigation-menu-item.ts index 85be0bf..6eda75e 100644 --- a/src/components/navigation-menu/types/navigation-menu-item.ts +++ b/src/components/navigation-menu/types/navigation-menu-item.ts @@ -1,9 +1,8 @@ -import { NavigationMenuItem as NavigationMenuItemPrimitive } from "@radix-ui/react-navigation-menu"; -import React from "react"; +import { NavigationMenuItem as NavigationMenuItemPrimitive } from '@radix-ui/react-navigation-menu' +import React from 'react' -type NavigationMenuItemPrimitiveType = typeof NavigationMenuItemPrimitive; +type NavigationMenuItemPrimitiveType = typeof NavigationMenuItemPrimitive -type NavigationMenuItemProps = - React.ComponentPropsWithRef; +type NavigationMenuItemProps = React.ComponentPropsWithRef -export type { NavigationMenuItemProps }; +export type { NavigationMenuItemProps } diff --git a/src/components/navigation-menu/types/navigation-menu-link.ts b/src/components/navigation-menu/types/navigation-menu-link.ts index a22eadb..b0c764d 100644 --- a/src/components/navigation-menu/types/navigation-menu-link.ts +++ b/src/components/navigation-menu/types/navigation-menu-link.ts @@ -1,21 +1,16 @@ -import { NavigationMenuLink as NavigationMenuLinkPrimitive } from "@radix-ui/react-navigation-menu"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { NavigationMenuLink as NavigationMenuLinkPrimitive } from '@radix-ui/react-navigation-menu' +import { Simplify } from '@/components/_shared/types/simplify' -import { ButtonProps } from "@/components/button"; +import { ButtonProps } from '@/components/button' type NavigationMenuLinkPrimitiveProps = React.ComponentPropsWithRef< - typeof NavigationMenuLinkPrimitive ->; + typeof NavigationMenuLinkPrimitive +> -type NavigationMenuLinkButtonProps = ButtonProps; +type NavigationMenuLinkButtonProps = ButtonProps -type NavigationMenuLinkLinkProps = Pick< - NavigationMenuLinkPrimitiveProps, - "active" | "onSelect" ->; +type NavigationMenuLinkLinkProps = Pick -type NavigationMenuLinkProps = Simplify< - NavigationMenuLinkButtonProps & NavigationMenuLinkLinkProps ->; +type NavigationMenuLinkProps = Simplify -export type { NavigationMenuLinkProps }; +export type { NavigationMenuLinkProps } diff --git a/src/components/navigation-menu/types/navigation-menu-trigger.ts b/src/components/navigation-menu/types/navigation-menu-trigger.ts index a507720..5d1c16f 100644 --- a/src/components/navigation-menu/types/navigation-menu-trigger.ts +++ b/src/components/navigation-menu/types/navigation-menu-trigger.ts @@ -1,27 +1,23 @@ -import { ButtonProps } from "@/components/button"; -import { NavigationMenuTriggerIndicator } from "@/components/navigation-menu/components/navigation-menu-trigger-indicator"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { ButtonProps } from '@/components/button' +import { NavigationMenuTriggerIndicator } from '@/components/navigation-menu/components/navigation-menu-trigger-indicator' +import { Simplify } from '@/components/_shared/types/simplify' type NavigationMenuTriggerRenderProps = { - Indicator: typeof NavigationMenuTriggerIndicator; - indicatorProps: - | React.ComponentProps - | undefined; -}; -type NavigationMenuTriggerButtonProps = Omit & { - children?: - | ((props: NavigationMenuTriggerRenderProps) => React.ReactNode) - | React.ReactNode; -}; + Indicator: typeof NavigationMenuTriggerIndicator + indicatorProps: React.ComponentProps | undefined +} +type NavigationMenuTriggerButtonProps = Omit & { + children?: ((props: NavigationMenuTriggerRenderProps) => React.ReactNode) | React.ReactNode +} type NavigationMenuTriggerCustomProps = { - indicator?: React.ReactNode; - indicatorProps?: React.ComponentProps; - hasIndicator?: boolean; -}; + indicator?: React.ReactNode + indicatorProps?: React.ComponentProps + hasIndicator?: boolean +} type NavigationMenuTriggerProps = Simplify< - NavigationMenuTriggerButtonProps & NavigationMenuTriggerCustomProps ->; + NavigationMenuTriggerButtonProps & NavigationMenuTriggerCustomProps +> -export type { NavigationMenuTriggerProps }; +export type { NavigationMenuTriggerProps } diff --git a/src/components/navigation-menu/types/navigation-menu.ts b/src/components/navigation-menu/types/navigation-menu.ts index e198bcf..4c7728c 100644 --- a/src/components/navigation-menu/types/navigation-menu.ts +++ b/src/components/navigation-menu/types/navigation-menu.ts @@ -1,51 +1,45 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' import { - NavigationMenuIndicator as NavigationMenuIndicatorPrimitive, - NavigationMenuList as NavigationMenuListPrimitive, - NavigationMenu as NavigationMenuPrimitive, - NavigationMenuViewport as NavigationMenuViewportPrimitive, -} from "@radix-ui/react-navigation-menu"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; -import React from "react"; + NavigationMenuIndicator as NavigationMenuIndicatorPrimitive, + NavigationMenuList as NavigationMenuListPrimitive, + NavigationMenu as NavigationMenuPrimitive, + NavigationMenuViewport as NavigationMenuViewportPrimitive, +} from '@radix-ui/react-navigation-menu' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' +import React from 'react' -type NavigationMenuPrimitiveType = typeof NavigationMenuPrimitive; +type NavigationMenuPrimitiveType = typeof NavigationMenuPrimitive -type NavigationMenuIndicatorPrimitiveType = - typeof NavigationMenuIndicatorPrimitive; +type NavigationMenuIndicatorPrimitiveType = typeof NavigationMenuIndicatorPrimitive -type NavigationMenuListPrimitiveType = typeof NavigationMenuListPrimitive; +type NavigationMenuListPrimitiveType = typeof NavigationMenuListPrimitive -type NavigationMenuViewportPrimitiveType = - typeof NavigationMenuViewportPrimitive; +type NavigationMenuViewportPrimitiveType = typeof NavigationMenuViewportPrimitive -type NavigationMenuPrimitiveProps = - React.ComponentPropsWithRef; +type NavigationMenuPrimitiveProps = React.ComponentPropsWithRef type NavigationMenuIndicatorPrimitiveProps = - React.ComponentPropsWithRef; + React.ComponentPropsWithRef -type NavigationMenuIndicatorArrowProps = React.ComponentPropsWithRef<"div">; +type NavigationMenuIndicatorArrowProps = React.ComponentPropsWithRef<'div'> -type NavigationMenuListPrimitiveProps = - React.ComponentPropsWithRef; +type NavigationMenuListPrimitiveProps = React.ComponentPropsWithRef -type NavigationMenuViewportContainerProps = React.ComponentPropsWithRef<"div">; +type NavigationMenuViewportContainerProps = React.ComponentPropsWithRef<'div'> type NavigationMenuViewportPrimitiveProps = - React.ComponentPropsWithRef; + React.ComponentPropsWithRef type NavigationMenuRenderUIProps = { - listProps?: NavigationMenuListPrimitiveProps; - isFullScreen?: boolean; - viewportContainerProps?: NavigationMenuViewportContainerProps; - viewportProps?: NavigationMenuViewportPrimitiveProps; - hasIndicator?: boolean; - indicatorProps?: NavigationMenuIndicatorPrimitiveProps; - indicatorArrowProps?: NavigationMenuIndicatorArrowProps; -} & AnimationStyleVariables; - -type NavigationMenuProps = Simplify< - NavigationMenuPrimitiveProps & NavigationMenuRenderUIProps ->; - -export type { NavigationMenuProps }; + listProps?: NavigationMenuListPrimitiveProps + isFullScreen?: boolean + viewportContainerProps?: NavigationMenuViewportContainerProps + viewportProps?: NavigationMenuViewportPrimitiveProps + hasIndicator?: boolean + indicatorProps?: NavigationMenuIndicatorPrimitiveProps + indicatorArrowProps?: NavigationMenuIndicatorArrowProps +} & AnimationStyleVariables + +type NavigationMenuProps = Simplify + +export type { NavigationMenuProps } diff --git a/src/components/number-input/components/number-input.tsx b/src/components/number-input/components/number-input.tsx index 99a691b..31e4cd1 100644 --- a/src/components/number-input/components/number-input.tsx +++ b/src/components/number-input/components/number-input.tsx @@ -1,55 +1,50 @@ -"use client"; +'use client' -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { Aria } from "@/components/aria"; -import { NumberSpinButton } from "@/components/number-input/components/number-spin-button"; -import { useNumberInput } from "@/components/number-input/hooks/use-number-input"; -import { NumberInputProps } from "@/components/number-input/types/number-input"; -import { Separator } from "@/components/separator"; +import { Aria } from '@/components/aria' +import { NumberSpinButton } from '@/components/number-input/components/number-spin-button' +import { useNumberInput } from '@/components/number-input/hooks/use-number-input' +import { NumberInputProps } from '@/components/number-input/types/number-input' +import { Separator } from '@/components/separator' const NumberInput = (props: NumberInputProps) => { - const { - inputContainerProps, - inputProps, - spinButtonContainerProps, - incrementButtonProps, - decrementButtonProps, - separatorProps, - utilityProps, - } = useNumberInput(props); - - const { hasSpinButtons, startContent, children, endContent } = utilityProps; - - const { asChild: inputAsChild, ...restInputProps } = inputProps; - - const { - asChild: spinButtonContainerAsChild, - ...restSpinButtonContainerProps - } = spinButtonContainerProps; - - const InputComponent = polymorphic(inputAsChild, "input"); - const SpinButtonContainerComponent = polymorphic( - spinButtonContainerAsChild, - "div" - ); - - return ( - - {startContent} - - {hasSpinButtons ? ( - - - - - - ) : null} - {children} - {endContent} - - ); -}; - -export { NumberInput }; + const { + inputContainerProps, + inputProps, + spinButtonContainerProps, + incrementButtonProps, + decrementButtonProps, + separatorProps, + utilityProps, + } = useNumberInput(props) + + const { hasSpinButtons, startContent, children, endContent } = utilityProps + + const { asChild: inputAsChild, ...restInputProps } = inputProps + + const { asChild: spinButtonContainerAsChild, ...restSpinButtonContainerProps } = + spinButtonContainerProps + + const InputComponent = polymorphic(inputAsChild, 'input') + const SpinButtonContainerComponent = polymorphic(spinButtonContainerAsChild, 'div') + + return ( + + {startContent} + + {hasSpinButtons ? ( + + + + + + ) : null} + {children} + {endContent} + + ) +} + +export { NumberInput } diff --git a/src/components/number-input/components/number-spin-button.tsx b/src/components/number-input/components/number-spin-button.tsx index 0c2cdd4..33bf7e8 100644 --- a/src/components/number-input/components/number-spin-button.tsx +++ b/src/components/number-input/components/number-spin-button.tsx @@ -3,49 +3,49 @@ import React from 'react' import { Button } from '@/components/button' import { - DEFAULT_NUMBER_SPIN_BUTTON_CLASSNAME, - DEFAULT_NUMBER_SPIN_BUTTON_ICON_CLASSNAME, + DEFAULT_NUMBER_SPIN_BUTTON_CLASSNAME, + DEFAULT_NUMBER_SPIN_BUTTON_ICON_CLASSNAME, } from '@/components/number-input/constants/constants' import { NumberSpinButtonProps } from '@/components/number-input/types/number-spin-button' import { ChevronDownIcon } from '@/components/_shared/components/icons/chevron-down-icon' import { ChevronUpIcon } from '@/components/_shared/components/icons/chevron-up-icon' const NumberSpinButton = (props: NumberSpinButtonProps) => { - const { - children, - className, - variant = 'plain', - action = 'increment', - tabIndex = -1, - longPressTreshold = 100, - isLongPressDisabled = false, - preventFocusOnPress = true, - hasDefaultPressedStyles = false, - ...restProps - } = props + const { + children, + className, + variant = 'plain', + action = 'increment', + tabIndex = -1, + longPressTreshold = 100, + isLongPressDisabled = false, + preventFocusOnPress = true, + hasDefaultPressedStyles = false, + ...restProps + } = props - const renderChildren = () => { - if (action === 'increment') { - return - } + const renderChildren = () => { + if (action === 'increment') { + return + } - return - } + return + } - return ( - - ) + return ( + + ) } export { NumberSpinButton } diff --git a/src/components/number-input/constants/constants.ts b/src/components/number-input/constants/constants.ts index 608d9db..809795a 100644 --- a/src/components/number-input/constants/constants.ts +++ b/src/components/number-input/constants/constants.ts @@ -16,37 +16,37 @@ const DEFAULT_NUMBER_SPIN_BUTTON_ICON_CLASSNAME = 'pointer-events-none relative const DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME = 'render-ui-number-input-container' const DEFAULT_NUMBER_INPUT_CLASSNAME = - 'render-ui-number-input relative z-[1] text-sm pl-3 pr-[44px] appearence-none text-mode-contrast bg-transparent outline-none text-elipsis overflow-hidden min-w-[0px] h-full w-full data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' + 'render-ui-number-input relative z-[1] text-sm pl-3 pr-[44px] appearence-none text-mode-contrast bg-transparent outline-none text-elipsis overflow-hidden min-w-[0px] h-full w-full data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' const DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME = - 'render-ui-number-input-spin-button-container render-ui-number-input-increment absolute right-0 top-0 flex h-full flex-col border-l p-0' + 'render-ui-number-input-spin-button-container render-ui-number-input-increment absolute right-0 top-0 flex h-full flex-col border-l p-0' const DEFAULT_NUMBER_SPIN_BUTTON_CLASSNAME = - 'render-ui-number-input-spin-button flex-1 rounded-none px-2 py-0 data-[hover=true]:bg-mode-accent/50 data-[pressed=true]:bg-mode-accent data-[long-pressed=true]:bg-mode-accent' + 'render-ui-number-input-spin-button flex-1 rounded-none px-2 py-0 data-[hover=true]:bg-mode-accent/50 data-[pressed=true]:bg-mode-accent data-[long-pressed=true]:bg-mode-accent' const DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME = - 'render-ui-number-input-increment-button render-ui-number-input-spin-button top-[1px]' + 'render-ui-number-input-increment-button render-ui-number-input-spin-button top-[1px]' const DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME = - 'render-ui-number-input-increment-button render-ui-number-input-spin-button top-[-1px]' + 'render-ui-number-input-increment-button render-ui-number-input-spin-button top-[-1px]' const SEPARATOR_OUTLINE_CLASSNAME = 'h-[2px] bg-mode-accent border-none' export { - ACCELERATED_SPIN_HOLD_TIMEOUT, - ACCELERATED_SPIN_TRESHOLD_TIMEOUT, - DEFAULT_NUMBER_INPUT_CLASSNAME, - DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, - DEFAULT_NUMBER_SPIN_BUTTON_ICON_CLASSNAME, - DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, - FORBIDDEN_INPUT_CHARACTERS, - HOLDING_SPIN_TIMEOUT, - INITIAL_SPIN_HOLD_TIMEOUT, - INITIAL_SPIN_TRESHOLD_TIMEOUT, - NUMERIC_REGEX, - SPIN_TIMEOUT, - DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, - DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, - SEPARATOR_OUTLINE_CLASSNAME, - DEFAULT_NUMBER_SPIN_BUTTON_CLASSNAME, + ACCELERATED_SPIN_HOLD_TIMEOUT, + ACCELERATED_SPIN_TRESHOLD_TIMEOUT, + DEFAULT_NUMBER_INPUT_CLASSNAME, + DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, + DEFAULT_NUMBER_SPIN_BUTTON_ICON_CLASSNAME, + DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, + FORBIDDEN_INPUT_CHARACTERS, + HOLDING_SPIN_TIMEOUT, + INITIAL_SPIN_HOLD_TIMEOUT, + INITIAL_SPIN_TRESHOLD_TIMEOUT, + NUMERIC_REGEX, + SPIN_TIMEOUT, + DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, + DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, + SEPARATOR_OUTLINE_CLASSNAME, + DEFAULT_NUMBER_SPIN_BUTTON_CLASSNAME, } diff --git a/src/components/number-input/hooks/use-number-input.ts b/src/components/number-input/hooks/use-number-input.ts index aba1d87..3f744fd 100644 --- a/src/components/number-input/hooks/use-number-input.ts +++ b/src/components/number-input/hooks/use-number-input.ts @@ -1,280 +1,259 @@ -import { - chain, - cn, - cx, - functionCallOrValue, - getOptionalObject, -} from "@renderui/utils"; -import React from "react"; +import { chain, cn, cx, functionCallOrValue, getOptionalObject } from '@renderui/utils' +import React from 'react' -import { inputContainerClasses } from "@/components/_shared/classes/input-container-classes"; -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { useMergedRef } from "@/components/_shared/hooks/use-merged-ref"; -import { useOnClickOutside } from "@/components/_shared/hooks/use-on-click-outside"; -import { focusInput } from "@/components/_shared/utils/focus-input"; +import { inputContainerClasses } from '@/components/_shared/classes/input-container-classes' +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' +import { useOnClickOutside } from '@/components/_shared/hooks/use-on-click-outside' +import { focusInput } from '@/components/_shared/utils/focus-input' import { - DEFAULT_NUMBER_INPUT_CLASSNAME, - DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, - DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, - DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, - DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, - SEPARATOR_OUTLINE_CLASSNAME, -} from "@/components/number-input/constants/constants"; -import { useNumberSpin } from "@/components/number-input/hooks/use-number-spin"; -import { getOnChange } from "@/components/number-input/hooks/use-on-change"; -import { NumberInputProps } from "@/components/number-input/types/number-input"; -import { getHandleKeyPressCapture } from "@/components/number-input/utils/get-handle-key-press-capture"; + DEFAULT_NUMBER_INPUT_CLASSNAME, + DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, + DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, + DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, + DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, + SEPARATOR_OUTLINE_CLASSNAME, +} from '@/components/number-input/constants/constants' +import { useNumberSpin } from '@/components/number-input/hooks/use-number-spin' +import { getOnChange } from '@/components/number-input/hooks/use-on-change' +import { NumberInputProps } from '@/components/number-input/types/number-input' +import { getHandleKeyPressCapture } from '@/components/number-input/utils/get-handle-key-press-capture' function useNumberInput(props: NumberInputProps) { - const { - ref, - min, - max, - pattern, - className, - children, - startContent, - endContent, - isDisabled, - isReadOnly, - isInvalid, - isRequired, - inputContainerProps, - spinButtonContainerProps, - incrementButtonProps, - decrementButtonProps, - separatorProps, - onClick, - onMouseDown, - onKeyDownCapture, - onValueChange, - onPointerDown, - onChange: nativeOnChange, - onSpin, - onSpinIncrement, - onSpinDecrement, - value: valueProp, - step = "1", - size = "md", - variant = "solid", - defaultValue = "", - hasSpinButtons = true, - ...restProps - } = props; + const { + ref, + min, + max, + pattern, + className, + children, + startContent, + endContent, + isDisabled, + isReadOnly, + isInvalid, + isRequired, + inputContainerProps, + spinButtonContainerProps, + incrementButtonProps, + decrementButtonProps, + separatorProps, + onClick, + onMouseDown, + onKeyDownCapture, + onValueChange, + onPointerDown, + onChange: nativeOnChange, + onSpin, + onSpinIncrement, + onSpinDecrement, + value: valueProp, + step = '1', + size = 'md', + variant = 'solid', + defaultValue = '', + hasSpinButtons = true, + ...restProps + } = props - const [value, setValue] = useControllableState({ - prop: valueProp as string, - defaultProp: defaultValue as string, - onChange: onValueChange, - }); + const [value, setValue] = useControllableState({ + prop: valueProp as string, + defaultProp: defaultValue as string, + onChange: onValueChange, + }) - const internalInputRef = React.useRef(null); - const mergedRefCallback = useMergedRef([ - internalInputRef, - ref, - ]); + const internalInputRef = React.useRef(null) + const mergedRefCallback = useMergedRef([internalInputRef, ref]) - const { - increment, - incrementWithVariableSpeed, - decrement, - decrementWithVariableSpeed, - stopIncrementing, - stopDecrementing, - clearIntervals, - } = useNumberSpin( - { - value, - min, - max, - step, - pattern, - setValue, - onSpin, - onSpinIncrement, - onSpinDecrement, - }, - internalInputRef - ); + const { + increment, + incrementWithVariableSpeed, + decrement, + decrementWithVariableSpeed, + stopIncrementing, + stopDecrementing, + clearIntervals, + } = useNumberSpin( + { + value, + min, + max, + step, + pattern, + setValue, + onSpin, + onSpinIncrement, + onSpinDecrement, + }, + internalInputRef, + ) - useOnClickOutside({ - event: "pointerdown", - element: internalInputRef.current, - handler: clearIntervals, - }); + useOnClickOutside({ + event: 'pointerdown', + element: internalInputRef.current, + handler: clearIntervals, + }) - const { - className: inputContainerClassName, - onPointerDown: inputContainerOnPointerDown, - onClick: inputContainerOnClick, - isTextInput = true, - isFocusWithin = true, - isUsingAriaPressProps = false, - ...restInputContainerProps - } = getOptionalObject(inputContainerProps); + const { + className: inputContainerClassName, + onPointerDown: inputContainerOnPointerDown, + onClick: inputContainerOnClick, + isTextInput = true, + isFocusWithin = true, + isUsingAriaPressProps = false, + ...restInputContainerProps + } = getOptionalObject(inputContainerProps) - const { - className: spinButtonContainerClassName, - ...restSpinButtonContainerClassName - } = getOptionalObject(spinButtonContainerProps); + const { className: spinButtonContainerClassName, ...restSpinButtonContainerClassName } = + getOptionalObject(spinButtonContainerProps) - const { - className: incrementButtonClassName, - onPress: incrementButtonOnPress, - onLongPress: incrementOnLongPress, - onPointerUp: incrementOnPointerUp, - onPointerLeave: incrementOnPointerLeave, - onPointerCancel: incrementOnPointerCancel, - ...restIncrementButtonClassName - } = getOptionalObject(incrementButtonProps); + const { + className: incrementButtonClassName, + onPress: incrementButtonOnPress, + onLongPress: incrementOnLongPress, + onPointerUp: incrementOnPointerUp, + onPointerLeave: incrementOnPointerLeave, + onPointerCancel: incrementOnPointerCancel, + ...restIncrementButtonClassName + } = getOptionalObject(incrementButtonProps) - const { - className: decrementButtonClassName, - onPress: decrementButtonOnPress, - onLongPress: decrementOnLongPress, - onPointerUp: decrementOnPointerUp, - onPointerLeave: decrementOnPointerLeave, - onPointerCancel: decrementOnPointerCancel, - ...restDecrementButtonClassName - } = getOptionalObject(decrementButtonProps); + const { + className: decrementButtonClassName, + onPress: decrementButtonOnPress, + onLongPress: decrementOnLongPress, + onPointerUp: decrementOnPointerUp, + onPointerLeave: decrementOnPointerLeave, + onPointerCancel: decrementOnPointerCancel, + ...restDecrementButtonClassName + } = getOptionalObject(decrementButtonProps) - const { className: separatorClassName, ...restSeparatorProps } = - getOptionalObject(separatorProps); + const { className: separatorClassName, ...restSeparatorProps } = getOptionalObject(separatorProps) - const forcedVariant = variant === "outline" ? "outline" : "solid"; + const forcedVariant = variant === 'outline' ? 'outline' : 'solid' - return { - inputContainerProps: { - isTextInput, - isFocusWithin, - isDisabled, - isUsingAriaPressProps, - "data-disabled": isDisabled, - "data-read-only": isReadOnly, - "data-invalid": isInvalid, - "data-required": isRequired, - "data-slot": "base", - className: cx( - DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, - inputContainerClasses({ size, variant: forcedVariant }), - inputContainerClassName - ), - onPointerDown: chain( - (event: React.PointerEvent) => event.preventDefault(), - inputContainerOnPointerDown - ), - onClick: chain(() => focusInput(internalInputRef), inputContainerOnClick), - ...restInputContainerProps, - }, - inputProps: { - pattern, - min, - max, - step, - ref: mergedRefCallback, - value: value ?? "", - role: "spinbutton", - inputMode: "numeric", - "aria-valuemin": min ? Number(min) : undefined, - "aria-valuemax": max ? Number(max) : undefined, - "aria-valuenow": value ? Number(value) : undefined, - "aria-required": isRequired, - "aria-disabled": isDisabled, - "aria-readonly": isReadOnly, - "aria-invalid": isInvalid, - "data-disabled": isDisabled, - "data-read-only": isReadOnly, - "data-invalid": isInvalid, - "data-required": isRequired, - "data-slot": "input", - disabled: isDisabled, - readOnly: isReadOnly, - className: cn(DEFAULT_NUMBER_INPUT_CLASSNAME, className), - onChange: getOnChange({ - min, - max, - pattern, - setValue, - onChange: nativeOnChange, - }), - onPointerDown: chain( - onPointerDown, - (event: React.PointerEvent) => event.stopPropagation() - ), - onKeyDownCapture: chain( - getHandleKeyPressCapture({ - min, - max, - step, - pattern, - setValue, - }), - onKeyDownCapture - ), - onClick: chain( - (event: React.MouseEvent) => - event.stopPropagation(), - onClick - ), - onMouseDown: chain( - (event: React.MouseEvent) => - event.stopPropagation(), - onMouseDown - ), - ...restProps, - } as const, - spinButtonContainerProps: { - className: cn( - DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, - forcedVariant === "outline" ? "border-mode-accent" : "border-separator", - spinButtonContainerClassName - ), - "data-slot": "spin-button-container", - ...restSpinButtonContainerClassName, - }, - incrementButtonProps: { - action: "increment", - "data-slot": "increment-button", - className: cx( - DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, - incrementButtonClassName - ), - onPress: chain(increment, incrementButtonOnPress), - onLongPress: chain(incrementWithVariableSpeed, incrementOnLongPress), - onPointerUp: chain(stopIncrementing, incrementOnPointerUp), - onPointerLeave: chain(stopIncrementing, incrementOnPointerLeave), - onPointerCancel: chain(stopIncrementing, incrementOnPointerCancel), - ...restIncrementButtonClassName, - } as const, - decrementButtonProps: { - action: "decrement", - "data-slot": "decrement-button", - className: cx( - DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, - decrementButtonClassName - ), - onPress: chain(decrement, decrementButtonOnPress), - onLongPress: chain(decrementWithVariableSpeed, decrementOnLongPress), - onPointerUp: chain(stopDecrementing, decrementOnPointerUp), - onPointerLeave: chain(stopDecrementing, decrementOnPointerLeave), - onPointerCancel: chain(stopDecrementing, decrementOnPointerCancel), - ...restDecrementButtonClassName, - } as const, - separatorProps: { - "data-slot": "separator", - className: cx( - forcedVariant === "outline" ? SEPARATOR_OUTLINE_CLASSNAME : "", - separatorClassName - ), - ...restSeparatorProps, - }, - utilityProps: { - startContent: functionCallOrValue(startContent, value ?? ""), - children: functionCallOrValue(children, value ?? ""), - endContent: functionCallOrValue(endContent, value ?? ""), - hasSpinButtons, - }, - } as const; + return { + inputContainerProps: { + isTextInput, + isFocusWithin, + isDisabled, + isUsingAriaPressProps, + 'data-disabled': isDisabled, + 'data-read-only': isReadOnly, + 'data-invalid': isInvalid, + 'data-required': isRequired, + 'data-slot': 'base', + className: cx( + DEFAULT_NUMBER_INPUT_CONTAINER_CLASSNAME, + inputContainerClasses({ size, variant: forcedVariant }), + inputContainerClassName, + ), + onPointerDown: chain( + (event: React.PointerEvent) => event.preventDefault(), + inputContainerOnPointerDown, + ), + onClick: chain(() => focusInput(internalInputRef), inputContainerOnClick), + ...restInputContainerProps, + }, + inputProps: { + pattern, + min, + max, + step, + ref: mergedRefCallback, + value: value ?? '', + role: 'spinbutton', + inputMode: 'numeric', + 'aria-valuemin': min ? Number(min) : undefined, + 'aria-valuemax': max ? Number(max) : undefined, + 'aria-valuenow': value ? Number(value) : undefined, + 'aria-required': isRequired, + 'aria-disabled': isDisabled, + 'aria-readonly': isReadOnly, + 'aria-invalid': isInvalid, + 'data-disabled': isDisabled, + 'data-read-only': isReadOnly, + 'data-invalid': isInvalid, + 'data-required': isRequired, + 'data-slot': 'input', + disabled: isDisabled, + readOnly: isReadOnly, + className: cn(DEFAULT_NUMBER_INPUT_CLASSNAME, className), + onChange: getOnChange({ + min, + max, + pattern, + setValue, + onChange: nativeOnChange, + }), + onPointerDown: chain(onPointerDown, (event: React.PointerEvent) => + event.stopPropagation(), + ), + onKeyDownCapture: chain( + getHandleKeyPressCapture({ + min, + max, + step, + pattern, + setValue, + }), + onKeyDownCapture, + ), + onClick: chain( + (event: React.MouseEvent) => event.stopPropagation(), + onClick, + ), + onMouseDown: chain( + (event: React.MouseEvent) => event.stopPropagation(), + onMouseDown, + ), + ...restProps, + } as const, + spinButtonContainerProps: { + className: cn( + DFEAULT_NUMBER_INPUT_SPIN_BUTTON_CONTAINER_CLASSNAME, + forcedVariant === 'outline' ? 'border-mode-accent' : 'border-separator', + spinButtonContainerClassName, + ), + 'data-slot': 'spin-button-container', + ...restSpinButtonContainerClassName, + }, + incrementButtonProps: { + action: 'increment', + 'data-slot': 'increment-button', + className: cx(DEFAULT_NUMBER_INPUT_INCREMENT_BUTTON_CLASSNAME, incrementButtonClassName), + onPress: chain(increment, incrementButtonOnPress), + onLongPress: chain(incrementWithVariableSpeed, incrementOnLongPress), + onPointerUp: chain(stopIncrementing, incrementOnPointerUp), + onPointerLeave: chain(stopIncrementing, incrementOnPointerLeave), + onPointerCancel: chain(stopIncrementing, incrementOnPointerCancel), + ...restIncrementButtonClassName, + } as const, + decrementButtonProps: { + action: 'decrement', + 'data-slot': 'decrement-button', + className: cx(DEFAULT_NUMBER_INPUT_DECREMENT_BUTTON_CLASSNAME, decrementButtonClassName), + onPress: chain(decrement, decrementButtonOnPress), + onLongPress: chain(decrementWithVariableSpeed, decrementOnLongPress), + onPointerUp: chain(stopDecrementing, decrementOnPointerUp), + onPointerLeave: chain(stopDecrementing, decrementOnPointerLeave), + onPointerCancel: chain(stopDecrementing, decrementOnPointerCancel), + ...restDecrementButtonClassName, + } as const, + separatorProps: { + 'data-slot': 'separator', + className: cx( + forcedVariant === 'outline' ? SEPARATOR_OUTLINE_CLASSNAME : '', + separatorClassName, + ), + ...restSeparatorProps, + }, + utilityProps: { + startContent: functionCallOrValue(startContent, value ?? ''), + children: functionCallOrValue(children, value ?? ''), + endContent: functionCallOrValue(endContent, value ?? ''), + hasSpinButtons, + }, + } as const } -export { useNumberInput }; +export { useNumberInput } diff --git a/src/components/number-input/hooks/use-number-spin.ts b/src/components/number-input/hooks/use-number-spin.ts index 9041814..8a0047a 100644 --- a/src/components/number-input/hooks/use-number-spin.ts +++ b/src/components/number-input/hooks/use-number-spin.ts @@ -7,159 +7,159 @@ import { getNewIntervalDuration } from '@/components/number-input/utils/get-new- import { isValidValue } from '@/components/number-input/utils/is-valid-value' type UseNumberSpinArgs = { - value: NumberInputProps['value'] - min: NumberInputProps['min'] - max: NumberInputProps['max'] - step: NumberInputProps['step'] - pattern: NumberInputProps['pattern'] - setValue: React.Dispatch> - onSpin: NumberInputProps['onSpin'] - onSpinIncrement: NumberInputProps['onSpinIncrement'] - onSpinDecrement: NumberInputProps['onSpinDecrement'] + value: NumberInputProps['value'] + min: NumberInputProps['min'] + max: NumberInputProps['max'] + step: NumberInputProps['step'] + pattern: NumberInputProps['pattern'] + setValue: React.Dispatch> + onSpin: NumberInputProps['onSpin'] + onSpinIncrement: NumberInputProps['onSpinIncrement'] + onSpinDecrement: NumberInputProps['onSpinDecrement'] } function useNumberSpin(args: UseNumberSpinArgs, inputRef: React.RefObject) { - const { value, min, max, step, pattern, setValue, onSpin, onSpinIncrement, onSpinDecrement } = - args + const { value, min, max, step, pattern, setValue, onSpin, onSpinIncrement, onSpinDecrement } = + args - // track current value with a ref, used to be able to access the current value - // without the setValue callback function, safer access to current value as - // setValue can be any externaly passed setter - const currentValueRef = React.useRef(value as string) + // track current value with a ref, used to be able to access the current value + // without the setValue callback function, safer access to current value as + // setValue can be any externaly passed setter + const currentValueRef = React.useRef(value as string) - // update the current value when value chages - React.useEffect(() => { - currentValueRef.current = value as string - }, [value]) + // update the current value when value chages + React.useEffect(() => { + currentValueRef.current = value as string + }, [value]) - const clickTimeout = React.useRef(null) - const incrementInterval = React.useRef(null) - const decrementInterval = React.useRef(null) - const pressDuration = React.useRef(0) + const clickTimeout = React.useRef(null) + const incrementInterval = React.useRef(null) + const decrementInterval = React.useRef(null) + const pressDuration = React.useRef(0) - const focusInputOnClickTimeout = () => { - if (clickTimeout.current) { - clearTimeout(clickTimeout.current) - clickTimeout.current = null - } + const focusInputOnClickTimeout = () => { + if (clickTimeout.current) { + clearTimeout(clickTimeout.current) + clickTimeout.current = null + } - clickTimeout.current = setTimeout(() => { - if (inputRef.current) focusInput(inputRef) - }, SPIN_TIMEOUT) - } + clickTimeout.current = setTimeout(() => { + if (inputRef.current) focusInput(inputRef) + }, SPIN_TIMEOUT) + } - const handleSpin = ( - action: 'increment' | 'decrement', - onActionSpinHandler: ((value: string) => void) | undefined, - ) => { - const previousValue = - currentValueRef.current === undefined ? 0 : Number(currentValueRef.current) + const handleSpin = ( + action: 'increment' | 'decrement', + onActionSpinHandler: ((value: string) => void) | undefined, + ) => { + const previousValue = + currentValueRef.current === undefined ? 0 : Number(currentValueRef.current) - const getNewValue = () => { - const previousValueString = previousValue.toString() - const decimalIndex = previousValueString.indexOf('.') - const decimalPlaces = decimalIndex >= 0 ? previousValueString.length - decimalIndex - 1 : 0 + const getNewValue = () => { + const previousValueString = previousValue.toString() + const decimalIndex = previousValueString.indexOf('.') + const decimalPlaces = decimalIndex >= 0 ? previousValueString.length - decimalIndex - 1 : 0 - if (action === 'decrement') { - return (previousValue - Number(step)).toFixed(decimalPlaces) - } + if (action === 'decrement') { + return (previousValue - Number(step)).toFixed(decimalPlaces) + } - return (previousValue + Number(step)).toFixed(decimalPlaces) - } + return (previousValue + Number(step)).toFixed(decimalPlaces) + } - const newValue = getNewValue() + const newValue = getNewValue() - const isValid = isValidValue({ value: newValue, min, max, pattern }) + const isValid = isValidValue({ value: newValue, min, max, pattern }) - if (!isValid) { - setValue(String(previousValue) || '') + if (!isValid) { + setValue(String(previousValue) || '') - return - } + return + } - if (onSpin) onSpin(newValue) + if (onSpin) onSpin(newValue) - if (onActionSpinHandler) onActionSpinHandler(newValue) + if (onActionSpinHandler) onActionSpinHandler(newValue) - currentValueRef.current = newValue + currentValueRef.current = newValue - setValue(currentValueRef.current) + setValue(currentValueRef.current) - focusInputOnClickTimeout() - } + focusInputOnClickTimeout() + } - const increment = () => handleSpin('increment', onSpinIncrement) + const increment = () => handleSpin('increment', onSpinIncrement) - const decrement = () => handleSpin('decrement', onSpinDecrement) + const decrement = () => handleSpin('decrement', onSpinDecrement) - const incrementWithVariableSpeed = () => { - increment() + const incrementWithVariableSpeed = () => { + increment() - if (incrementInterval.current) clearInterval(incrementInterval.current) + if (incrementInterval.current) clearInterval(incrementInterval.current) - const newIntervalDuration = getNewIntervalDuration(pressDuration.current) + const newIntervalDuration = getNewIntervalDuration(pressDuration.current) - incrementInterval.current = setInterval(incrementWithVariableSpeed, newIntervalDuration) - pressDuration.current += newIntervalDuration // increase press duration - } + incrementInterval.current = setInterval(incrementWithVariableSpeed, newIntervalDuration) + pressDuration.current += newIntervalDuration // increase press duration + } - const stopIncrementing = () => { - if (incrementInterval.current) { - clearInterval(incrementInterval.current) - incrementInterval.current = null - focusInput(inputRef) - } + const stopIncrementing = () => { + if (incrementInterval.current) { + clearInterval(incrementInterval.current) + incrementInterval.current = null + focusInput(inputRef) + } - pressDuration.current = 0 // reset press duration - } + pressDuration.current = 0 // reset press duration + } - const decrementWithVariableSpeed = () => { - decrement() + const decrementWithVariableSpeed = () => { + decrement() - if (decrementInterval.current) clearInterval(decrementInterval.current) + if (decrementInterval.current) clearInterval(decrementInterval.current) - const newIntervalDuration = getNewIntervalDuration(pressDuration.current) + const newIntervalDuration = getNewIntervalDuration(pressDuration.current) - decrementInterval.current = setInterval(decrementWithVariableSpeed, newIntervalDuration) - pressDuration.current += newIntervalDuration // increase press duration - } + decrementInterval.current = setInterval(decrementWithVariableSpeed, newIntervalDuration) + pressDuration.current += newIntervalDuration // increase press duration + } - const stopDecrementing = () => { - if (decrementInterval.current) { - clearInterval(decrementInterval.current) - decrementInterval.current = null - focusInput(inputRef) - } + const stopDecrementing = () => { + if (decrementInterval.current) { + clearInterval(decrementInterval.current) + decrementInterval.current = null + focusInput(inputRef) + } - pressDuration.current = 0 // reset press duration - } + pressDuration.current = 0 // reset press duration + } - const clearIntervals = () => { - if (clickTimeout.current) { - clearTimeout(clickTimeout.current) - clickTimeout.current = null - } + const clearIntervals = () => { + if (clickTimeout.current) { + clearTimeout(clickTimeout.current) + clickTimeout.current = null + } - if (incrementInterval.current) { - clearInterval(incrementInterval.current) - incrementInterval.current = null - } + if (incrementInterval.current) { + clearInterval(incrementInterval.current) + incrementInterval.current = null + } - if (decrementInterval.current) { - clearInterval(decrementInterval.current) - decrementInterval.current = null - } - } + if (decrementInterval.current) { + clearInterval(decrementInterval.current) + decrementInterval.current = null + } + } - return { - increment, - decrement, - incrementWithVariableSpeed, - decrementWithVariableSpeed, - stopIncrementing, - stopDecrementing, - clearIntervals, - } + return { + increment, + decrement, + incrementWithVariableSpeed, + decrementWithVariableSpeed, + stopIncrementing, + stopDecrementing, + clearIntervals, + } } export { useNumberSpin } diff --git a/src/components/number-input/hooks/use-on-change.ts b/src/components/number-input/hooks/use-on-change.ts index 21b2fe2..0af3e6a 100644 --- a/src/components/number-input/hooks/use-on-change.ts +++ b/src/components/number-input/hooks/use-on-change.ts @@ -2,19 +2,19 @@ import { NumberInputProps } from '@/components/number-input/types/number-input' import { isValidValue } from '@/components/number-input/utils/is-valid-value' type UseOnChangeArgs = Pick & { - setValue: React.Dispatch> + setValue: React.Dispatch> } const getOnChange = - ({ min, max, pattern, setValue, onChange }: UseOnChangeArgs) => - (event: React.ChangeEvent) => { - const eventValue = event.target.value + ({ min, max, pattern, setValue, onChange }: UseOnChangeArgs) => + (event: React.ChangeEvent) => { + const eventValue = event.target.value - if (!isValidValue({ value: eventValue, min, max, pattern })) return + if (!isValidValue({ value: eventValue, min, max, pattern })) return - setValue(eventValue) + setValue(eventValue) - if (onChange) onChange(event) - } + if (onChange) onChange(event) + } export { getOnChange } diff --git a/src/components/number-input/types/number-input.ts b/src/components/number-input/types/number-input.ts index 8ed6fa2..e25fba4 100644 --- a/src/components/number-input/types/number-input.ts +++ b/src/components/number-input/types/number-input.ts @@ -1,49 +1,42 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { inputContainerClasses } from "@/components/_shared/classes/input-container-classes"; -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { Aria } from "@/components/aria"; -import { ButtonProps } from "@/components/button"; -import { SeparatorProps } from "@/components/separator"; +import { inputContainerClasses } from '@/components/_shared/classes/input-container-classes' +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { Aria } from '@/components/aria' +import { ButtonProps } from '@/components/button' +import { SeparatorProps } from '@/components/separator' type NumberInputPrimitiveProps = Omit< - React.ComponentPropsWithRef<"input">, - "children" | "disabled" | "readonly" | "required" ->; + React.ComponentPropsWithRef<'input'>, + 'children' | 'disabled' | 'readonly' | 'required' +> type NumberInputCustomProps = { - isRequired?: boolean; - isDisabled?: boolean; - isInvalid?: boolean; - isReadOnly?: boolean; - hasSpinButtons?: boolean; - children?: React.ReactNode | ((value: string) => React.ReactNode); - startContent?: React.ReactNode | ((value: string) => React.ReactNode); - endContent?: React.ReactNode | ((value: string) => React.ReactNode); - inputContainerProps?: React.ComponentPropsWithRef; - spinButtonContainerProps?: Simplify< - React.ComponentPropsWithRef<"div"> & AsChildProp - >; - incrementButtonProps?: ButtonProps; - decrementButtonProps?: ButtonProps; - separatorProps?: SeparatorProps; - onValueChange?: (value: string | undefined) => void; - onSpin?: (value: string | undefined) => void; - onSpinIncrement?: (value: string | undefined) => void; - onSpinDecrement?: (value: string | undefined) => void; -}; + isRequired?: boolean + isDisabled?: boolean + isInvalid?: boolean + isReadOnly?: boolean + hasSpinButtons?: boolean + children?: React.ReactNode | ((value: string) => React.ReactNode) + startContent?: React.ReactNode | ((value: string) => React.ReactNode) + endContent?: React.ReactNode | ((value: string) => React.ReactNode) + inputContainerProps?: React.ComponentPropsWithRef + spinButtonContainerProps?: Simplify & AsChildProp> + incrementButtonProps?: ButtonProps + decrementButtonProps?: ButtonProps + separatorProps?: SeparatorProps + onValueChange?: (value: string | undefined) => void + onSpin?: (value: string | undefined) => void + onSpinIncrement?: (value: string | undefined) => void + onSpinDecrement?: (value: string | undefined) => void +} -type NumberInputVariantProps = NonNullableVariantProps< - typeof inputContainerClasses ->; +type NumberInputVariantProps = NonNullableVariantProps type NumberInputProps = Simplify< - NumberInputPrimitiveProps & - NumberInputCustomProps & - NumberInputVariantProps & - AsChildProp ->; + NumberInputPrimitiveProps & NumberInputCustomProps & NumberInputVariantProps & AsChildProp +> -export type { NumberInputProps }; +export type { NumberInputProps } diff --git a/src/components/number-input/utils/get-handle-key-press-capture.ts b/src/components/number-input/utils/get-handle-key-press-capture.ts index b6ddf8d..a3e2b08 100644 --- a/src/components/number-input/utils/get-handle-key-press-capture.ts +++ b/src/components/number-input/utils/get-handle-key-press-capture.ts @@ -4,43 +4,43 @@ import { NumberInputProps } from '@/components/number-input/types/number-input' import { isValidValue } from '@/components/number-input/utils/is-valid-value' type GetHandleKeyPressCaptureArgs = { - min: NumberInputProps['min'] - max: NumberInputProps['max'] - step: NumberInputProps['step'] - pattern: NumberInputProps['pattern'] - setValue: React.Dispatch> + min: NumberInputProps['min'] + max: NumberInputProps['max'] + step: NumberInputProps['step'] + pattern: NumberInputProps['pattern'] + setValue: React.Dispatch> } function getHandleKeyPressCapture(props: GetHandleKeyPressCaptureArgs) { - const { min, max, step, pattern, setValue } = props + const { min, max, step, pattern, setValue } = props - const updateValue = (previousValue: string | undefined, increment: number) => { - const numericValue = Number(previousValue) - const safeValue = Number.isNaN(numericValue) ? 0 : numericValue + const updateValue = (previousValue: string | undefined, increment: number) => { + const numericValue = Number(previousValue) + const safeValue = Number.isNaN(numericValue) ? 0 : numericValue - const newValue = safeValue + increment + const newValue = safeValue + increment - const isValid = isValidValue({ - value: newValue.toString(), - min, - max, - pattern, - }) + const isValid = isValidValue({ + value: newValue.toString(), + min, + max, + pattern, + }) - return isValid ? String(newValue) : previousValue - } + return isValid ? String(newValue) : previousValue + } - return (event: React.KeyboardEvent) => { - if (event.key === 'ArrowUp') { - event.preventDefault() + return (event: React.KeyboardEvent) => { + if (event.key === 'ArrowUp') { + event.preventDefault() - setValue((previousValue) => updateValue(previousValue, Number(step))) - } else if (event.key === 'ArrowDown') { - event.preventDefault() + setValue((previousValue) => updateValue(previousValue, Number(step))) + } else if (event.key === 'ArrowDown') { + event.preventDefault() - setValue((previousValue) => updateValue(previousValue, -Number(step))) - } - } + setValue((previousValue) => updateValue(previousValue, -Number(step))) + } + } } export { getHandleKeyPressCapture } diff --git a/src/components/number-input/utils/get-new-interval-duration.ts b/src/components/number-input/utils/get-new-interval-duration.ts index 1c6a896..3f349ca 100644 --- a/src/components/number-input/utils/get-new-interval-duration.ts +++ b/src/components/number-input/utils/get-new-interval-duration.ts @@ -1,21 +1,21 @@ import { - ACCELERATED_SPIN_HOLD_TIMEOUT, - ACCELERATED_SPIN_TRESHOLD_TIMEOUT, - HOLDING_SPIN_TIMEOUT, - INITIAL_SPIN_HOLD_TIMEOUT, - INITIAL_SPIN_TRESHOLD_TIMEOUT, + ACCELERATED_SPIN_HOLD_TIMEOUT, + ACCELERATED_SPIN_TRESHOLD_TIMEOUT, + HOLDING_SPIN_TIMEOUT, + INITIAL_SPIN_HOLD_TIMEOUT, + INITIAL_SPIN_TRESHOLD_TIMEOUT, } from '@/components/number-input/constants/constants' function getNewIntervalDuration(duration: number) { - if (duration === INITIAL_SPIN_TRESHOLD_TIMEOUT) { - return INITIAL_SPIN_HOLD_TIMEOUT // initial delay of 500ms - } + if (duration === INITIAL_SPIN_TRESHOLD_TIMEOUT) { + return INITIAL_SPIN_HOLD_TIMEOUT // initial delay of 500ms + } - if (duration < ACCELERATED_SPIN_TRESHOLD_TIMEOUT) { - return ACCELERATED_SPIN_HOLD_TIMEOUT // then repeat once with delay of 100ms - } + if (duration < ACCELERATED_SPIN_TRESHOLD_TIMEOUT) { + return ACCELERATED_SPIN_HOLD_TIMEOUT // then repeat once with delay of 100ms + } - return HOLDING_SPIN_TIMEOUT // then repeat every 10ms + return HOLDING_SPIN_TIMEOUT // then repeat every 10ms } export { getNewIntervalDuration } diff --git a/src/components/number-input/utils/is-valid-value.ts b/src/components/number-input/utils/is-valid-value.ts index 84f733a..61717f3 100644 --- a/src/components/number-input/utils/is-valid-value.ts +++ b/src/components/number-input/utils/is-valid-value.ts @@ -2,37 +2,37 @@ import { NUMERIC_REGEX } from '@/components/number-input/constants/constants' import { NumberInputProps } from '@/components/number-input/types/number-input' type IsValidValueArgs = { - value: string | undefined - min: NumberInputProps['min'] - max: NumberInputProps['max'] - pattern: NumberInputProps['pattern'] + value: string | undefined + min: NumberInputProps['min'] + max: NumberInputProps['max'] + pattern: NumberInputProps['pattern'] } const isValidValue = (args: IsValidValueArgs) => { - const { value, min, max, pattern } = args + const { value, min, max, pattern } = args - if (value === undefined) return false + if (value === undefined) return false - if (!NUMERIC_REGEX.test(value)) return false + if (!NUMERIC_REGEX.test(value)) return false - // Convert the new value to a number - const numericValue = Number(value) + // Convert the new value to a number + const numericValue = Number(value) - // Convert min and max to numbers for comparison - const numericMin = min === undefined ? undefined : Number(min) - const numericMax = max === undefined ? undefined : Number(max) + // Convert min and max to numbers for comparison + const numericMin = min === undefined ? undefined : Number(min) + const numericMax = max === undefined ? undefined : Number(max) - // Check if the new value is within the min and max range - if ( - (numericMin !== undefined && numericValue < numericMin) || - (numericMax !== undefined && numericValue > numericMax) - ) { - return false - } + // Check if the new value is within the min and max range + if ( + (numericMin !== undefined && numericValue < numericMin) || + (numericMax !== undefined && numericValue > numericMax) + ) { + return false + } - // Check if the new value matches the pattern - // eslint-disable-next-line security/detect-non-literal-regexp - return !(pattern !== undefined && !new RegExp(pattern).test(value)) + // Check if the new value matches the pattern + // eslint-disable-next-line security/detect-non-literal-regexp + return !(pattern !== undefined && !new RegExp(pattern).test(value)) } export { isValidValue } diff --git a/src/components/overlay/components/overlay.tsx b/src/components/overlay/components/overlay.tsx index 09f1889..ac0e25c 100644 --- a/src/components/overlay/components/overlay.tsx +++ b/src/components/overlay/components/overlay.tsx @@ -1,45 +1,45 @@ -"use client"; +'use client' -import { DialogOverlay } from "@radix-ui/react-dialog"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { DialogOverlay } from '@radix-ui/react-dialog' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_OVERLAY_CLASSNAME } from "@/components/overlay/constants/constants"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; -import { OverlayProps } from "@/components/overlay/types/overlay"; +import { DEFAULT_OVERLAY_CLASSNAME } from '@/components/overlay/constants/constants' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' +import { OverlayProps } from '@/components/overlay/types/overlay' const Overlay = (props: OverlayProps) => { - const { - className, - style, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - ...restProps - } = props; + const { + className, + style, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + ...restProps + } = props - return ( - - ); -}; + return ( + + ) +} -export { Overlay }; +export { Overlay } diff --git a/src/components/overlay/constants/constants.ts b/src/components/overlay/constants/constants.ts index 3348282..455a378 100644 --- a/src/components/overlay/constants/constants.ts +++ b/src/components/overlay/constants/constants.ts @@ -1,4 +1,4 @@ const DEFAULT_OVERLAY_CLASSNAME = - 'render-ui-overlay duration-medium data-[state=open]:animate-overlay-fade-in data-[state=closed]:animate-overlay-fade-out fixed inset-0 z-50 bg-black/70' + 'render-ui-overlay duration-medium data-[state=open]:animate-overlay-fade-in data-[state=closed]:animate-overlay-fade-out fixed inset-0 z-50 bg-black/70' export { DEFAULT_OVERLAY_CLASSNAME } diff --git a/src/components/overlay/types/overlay.ts b/src/components/overlay/types/overlay.ts index e256f50..b266e1b 100644 --- a/src/components/overlay/types/overlay.ts +++ b/src/components/overlay/types/overlay.ts @@ -1,9 +1,8 @@ -import { DialogOverlay as OverlayPrimitive } from "@radix-ui/react-dialog"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { DialogOverlay as OverlayPrimitive } from '@radix-ui/react-dialog' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' -type OverlayPrimitiveType = typeof OverlayPrimitive; +type OverlayPrimitiveType = typeof OverlayPrimitive -type OverlayProps = React.ComponentPropsWithRef & - AnimationStyleVariables; +type OverlayProps = React.ComponentPropsWithRef & AnimationStyleVariables -export type { OverlayProps }; +export type { OverlayProps } diff --git a/src/components/popover/components/popover-content.tsx b/src/components/popover/components/popover-content.tsx index e771bed..5ed154c 100644 --- a/src/components/popover/components/popover-content.tsx +++ b/src/components/popover/components/popover-content.tsx @@ -1,117 +1,117 @@ -'use client' - -import { - PopoverArrow as PopoverArrowPrimitive, - PopoverContent as PopoverContentPrimitive, - PopoverPortal as PopoverPortalPrimitive, -} from '@radix-ui/react-popover' -import { cn, getOptionalObject } from '@renderui/utils' -import React from 'react' - -import { - DEFAULT_POPOVER_ARROW_CLASSNAME, - DEFAULT_POPOVER_ARROW_CONTAINER_CLASSNAME, - DEFAULT_POPOVER_CONTENT_CLASSNAME, - POPOVER_CONTENT_TRIGGER_HEIGHT_CLASSNAME, - POPOVER_CONTENT_TRIGGER_MAX_HEIGHT_CLASSNAME, - POPOVER_CONTENT_TRIGGER_MAX_WIDTH_CLASSNAME, - POPOVER_CONTENT_TRIGGER_MIN_HEIGHT_CLASSNAME, - POPOVER_CONTENT_TRIGGER_MIN_WIDTH_CLASSNAME, - POPOVER_CONTENT_TRIGGER_WIDTH_CLASSNAME, -} from '@/components/popover/constants/constants' -import { usePopoverContext } from '@/components/popover/contexts/popover-context' -import { PopoverContentProps, PopoverContentRef } from '@/components/popover/types/popover-content' -import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' -import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' - -const PopoverContent = React.forwardRef((props, ref) => { - const { - children, - style, - className, - portalContainer, - forceMount, - hasTriggerHeight, - hasTriggerWidth, - hasTriggerMinWidth, - hasTriggerMinHeight, - hasTriggerMaxWidth, - hasTriggerMaxHeight, - arrowProps, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - hasArrow = true, - align = 'center', - sideOffset = 4, - ...restProps - } = props - - const { className: arrowClassName, ...restArrowProps } = getOptionalObject(arrowProps) - - const { contentRef } = usePopoverContext() - - const mergedRefCallback = useMergedRef([contentRef, ref]) - - return ( - - - {children} - {hasArrow ? ( - - - - - - - - ) : null} - - - ) -}) - -PopoverContent.displayName = 'PopoverContent' - -export { PopoverContent } +'use client' + +import { + PopoverArrow as PopoverArrowPrimitive, + PopoverContent as PopoverContentPrimitive, + PopoverPortal as PopoverPortalPrimitive, +} from '@radix-ui/react-popover' +import { cn, getOptionalObject } from '@renderui/utils' +import React from 'react' + +import { + DEFAULT_POPOVER_ARROW_CLASSNAME, + DEFAULT_POPOVER_ARROW_CONTAINER_CLASSNAME, + DEFAULT_POPOVER_CONTENT_CLASSNAME, + POPOVER_CONTENT_TRIGGER_HEIGHT_CLASSNAME, + POPOVER_CONTENT_TRIGGER_MAX_HEIGHT_CLASSNAME, + POPOVER_CONTENT_TRIGGER_MAX_WIDTH_CLASSNAME, + POPOVER_CONTENT_TRIGGER_MIN_HEIGHT_CLASSNAME, + POPOVER_CONTENT_TRIGGER_MIN_WIDTH_CLASSNAME, + POPOVER_CONTENT_TRIGGER_WIDTH_CLASSNAME, +} from '@/components/popover/constants/constants' +import { usePopoverContext } from '@/components/popover/contexts/popover-context' +import { PopoverContentProps, PopoverContentRef } from '@/components/popover/types/popover-content' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' +import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' + +const PopoverContent = React.forwardRef((props, ref) => { + const { + children, + style, + className, + portalContainer, + forceMount, + hasTriggerHeight, + hasTriggerWidth, + hasTriggerMinWidth, + hasTriggerMinHeight, + hasTriggerMaxWidth, + hasTriggerMaxHeight, + arrowProps, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + hasArrow = true, + align = 'center', + sideOffset = 4, + ...restProps + } = props + + const { className: arrowClassName, ...restArrowProps } = getOptionalObject(arrowProps) + + const { contentRef } = usePopoverContext() + + const mergedRefCallback = useMergedRef([contentRef, ref]) + + return ( + + + {children} + {hasArrow ? ( + + + + + + + + ) : null} + + + ) +}) + +PopoverContent.displayName = 'PopoverContent' + +export { PopoverContent } diff --git a/src/components/popover/components/popover-trigger.tsx b/src/components/popover/components/popover-trigger.tsx index d30a3bb..2cbad2e 100644 --- a/src/components/popover/components/popover-trigger.tsx +++ b/src/components/popover/components/popover-trigger.tsx @@ -1,34 +1,34 @@ -"use client"; - -import { PopoverTrigger as PopoverTriggerPrimitive } from "@radix-ui/react-popover"; -import { cx } from "@renderui/utils"; -import React from "react"; - -import { Button } from "@/components/button"; -import { DEFAULT_POPOVER_TRIGGER_CLASSNAME } from "@/components/popover/constants/constants"; -import { PopoverTriggerProps } from "@/components/popover/types/popover-trigger"; - -const PopoverTrigger = (props: PopoverTriggerProps) => { - const { - className, - variant = "solid", - color = "mode-accent", - hasRipple = true, - ...restProps - } = props; - - return ( - - - - ) : null} - - - ); -}; + return ( + + + + {children} + {hasCloseButton ? ( + + + + ) : null} + + + ) +} -export { SheetContent }; +export { SheetContent } diff --git a/src/components/sheet/components/sheet-description.tsx b/src/components/sheet/components/sheet-description.tsx index 23cbb79..81592d3 100644 --- a/src/components/sheet/components/sheet-description.tsx +++ b/src/components/sheet/components/sheet-description.tsx @@ -1 +1 @@ -export { ModalDescription as SheetDescription } from "@/components/_shared/components/modal-description/modal-description"; +export { ModalDescription as SheetDescription } from '@/components/_shared/components/modal-description/modal-description' diff --git a/src/components/sheet/components/sheet-footer.tsx b/src/components/sheet/components/sheet-footer.tsx index babcb59..dacff7c 100644 --- a/src/components/sheet/components/sheet-footer.tsx +++ b/src/components/sheet/components/sheet-footer.tsx @@ -1 +1 @@ -export { ModalFooter as SheetFooter } from "@/components/_shared/components/modal-footer/modal-footer"; +export { ModalFooter as SheetFooter } from '@/components/_shared/components/modal-footer/modal-footer' diff --git a/src/components/sheet/components/sheet-header.tsx b/src/components/sheet/components/sheet-header.tsx index a66057a..7e338c1 100644 --- a/src/components/sheet/components/sheet-header.tsx +++ b/src/components/sheet/components/sheet-header.tsx @@ -1 +1 @@ -export { ModalHeader as SheetHeader } from "@/components/_shared/components/modal-header/modal-header"; +export { ModalHeader as SheetHeader } from '@/components/_shared/components/modal-header/modal-header' diff --git a/src/components/sheet/components/sheet-title.tsx b/src/components/sheet/components/sheet-title.tsx index 46549ad..923aa55 100644 --- a/src/components/sheet/components/sheet-title.tsx +++ b/src/components/sheet/components/sheet-title.tsx @@ -1 +1 @@ -export { ModalTitle as SheetTitle } from "@/components/_shared/components/modal-title/modal-title"; +export { ModalTitle as SheetTitle } from '@/components/_shared/components/modal-title/modal-title' diff --git a/src/components/sheet/components/sheet-trigger.tsx b/src/components/sheet/components/sheet-trigger.tsx index 60d689a..9137f17 100644 --- a/src/components/sheet/components/sheet-trigger.tsx +++ b/src/components/sheet/components/sheet-trigger.tsx @@ -1,34 +1,28 @@ -"use client"; +'use client' -import { DialogTrigger as SheetTriggerPrimitive } from "@radix-ui/react-dialog"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { DialogTrigger as SheetTriggerPrimitive } from '@radix-ui/react-dialog' +import { cn } from '@renderui/utils' +import React from 'react' -import { Button } from "@/components/button"; -import { DEFAULT_SHEET_TRIGGER_CLASSNAME } from "@/components/sheet/constants/constants"; -import { SheetTriggerProps } from "@/components/sheet/types/sheet-trigger"; +import { Button } from '@/components/button' +import { DEFAULT_SHEET_TRIGGER_CLASSNAME } from '@/components/sheet/constants/constants' +import { SheetTriggerProps } from '@/components/sheet/types/sheet-trigger' const SheetTrigger = (props: SheetTriggerProps) => { - const { - className, - children, - variant = "solid", - color = "mode-accent", - ...restProps - } = props; + const { className, children, variant = 'solid', color = 'mode-accent', ...restProps } = props - return ( - - - - ); -}; + return ( + + + + ) +} -export { SheetTrigger }; +export { SheetTrigger } diff --git a/src/components/sheet/components/sheet.tsx b/src/components/sheet/components/sheet.tsx index 7c89269..709f8ad 100644 --- a/src/components/sheet/components/sheet.tsx +++ b/src/components/sheet/components/sheet.tsx @@ -1,14 +1,14 @@ -"use client"; +'use client' -import { Dialog as SheetPrimitive } from "@radix-ui/react-dialog"; -import React from "react"; +import { Dialog as SheetPrimitive } from '@radix-ui/react-dialog' +import React from 'react' -import { SheetProps } from "@/components/sheet/types/sheet"; +import { SheetProps } from '@/components/sheet/types/sheet' const Sheet = (props: SheetProps) => { - const { isModal, ...restProps } = props; + const { isModal, ...restProps } = props - return ; -}; + return +} -export { Sheet }; +export { Sheet } diff --git a/src/components/sheet/constants/constants.ts b/src/components/sheet/constants/constants.ts index 9854931..a4f06ad 100644 --- a/src/components/sheet/constants/constants.ts +++ b/src/components/sheet/constants/constants.ts @@ -1,13 +1,13 @@ const DEFAULT_SHEET_TRIGGER_CLASSNAME = 'render-ui-sheet-trigger' const DEFAULT_SHEET_CLOSE_BUTTON_CLASSNAME = - 'render-ui-sheet-close-button absolute right-4 top-4 p-2' + 'render-ui-sheet-close-button absolute right-4 top-4 p-2' const DEFAULT_SHEET_CLOSE_BUTTON_ICON_CLASSNAME = - 'render-ui-sheet-close-button-icon h-4 w-4 opacity-70' + 'render-ui-sheet-close-button-icon h-4 w-4 opacity-70' export { - DEFAULT_SHEET_CLOSE_BUTTON_CLASSNAME, - DEFAULT_SHEET_CLOSE_BUTTON_ICON_CLASSNAME, - DEFAULT_SHEET_TRIGGER_CLASSNAME, + DEFAULT_SHEET_CLOSE_BUTTON_CLASSNAME, + DEFAULT_SHEET_CLOSE_BUTTON_ICON_CLASSNAME, + DEFAULT_SHEET_TRIGGER_CLASSNAME, } diff --git a/src/components/sheet/index.ts b/src/components/sheet/index.ts index 378b33e..5b95c6c 100644 --- a/src/components/sheet/index.ts +++ b/src/components/sheet/index.ts @@ -9,4 +9,4 @@ export * from '@/components/sheet/components/sheet-title' export * from '@/components/sheet/components/sheet-trigger' export * from '@/components/sheet/types/sheet' export * from '@/components/sheet/types/sheet-content' -export * from '@/components/sheet/types/sheet-trigger' \ No newline at end of file +export * from '@/components/sheet/types/sheet-trigger' diff --git a/src/components/sheet/types/sheet-content.ts b/src/components/sheet/types/sheet-content.ts index 7d70bc1..d6c6049 100644 --- a/src/components/sheet/types/sheet-content.ts +++ b/src/components/sheet/types/sheet-content.ts @@ -1,33 +1,27 @@ import { - DialogContent as SheetContentPrimitive, - DialogPortal as SheetPortalPrimitive, -} from "@radix-ui/react-dialog"; -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; + DialogContent as SheetContentPrimitive, + DialogPortal as SheetPortalPrimitive, +} from '@radix-ui/react-dialog' +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { CrossSmallIcon } from "@/components/_shared/components/icons/cross-small-icon"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { ButtonProps } from "@/components/button"; -import { OverlayProps } from "@/components/overlay"; -import { sheetClasses } from "@/components/sheet/classes/sheet-classes"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { CrossSmallIcon } from '@/components/_shared/components/icons/cross-small-icon' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { ButtonProps } from '@/components/button' +import { OverlayProps } from '@/components/overlay' +import { sheetClasses } from '@/components/sheet/classes/sheet-classes' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' -type SheetContentPrimitiveProps = React.ComponentPropsWithRef< - typeof SheetContentPrimitive ->; +type SheetContentPrimitiveProps = React.ComponentPropsWithRef -type SheetContentRenderUIProps = NonNullableVariantProps< - typeof sheetClasses -> & { - portalProps?: React.ComponentPropsWithRef; - overlayProps?: OverlayProps; - closeButtonProps?: ButtonProps; - closeButtonIconProps?: React.ComponentPropsWithRef; - hasCloseButton?: boolean; -} & AnimationStyleVariables; +type SheetContentRenderUIProps = NonNullableVariantProps & { + portalProps?: React.ComponentPropsWithRef + overlayProps?: OverlayProps + closeButtonProps?: ButtonProps + closeButtonIconProps?: React.ComponentPropsWithRef + hasCloseButton?: boolean +} & AnimationStyleVariables -type SheetContentProps = Simplify< - SheetContentPrimitiveProps & SheetContentRenderUIProps ->; +type SheetContentProps = Simplify -export type { SheetContentProps }; +export type { SheetContentProps } diff --git a/src/components/sheet/types/sheet-trigger.ts b/src/components/sheet/types/sheet-trigger.ts index 9f91b8a..5a6977b 100644 --- a/src/components/sheet/types/sheet-trigger.ts +++ b/src/components/sheet/types/sheet-trigger.ts @@ -1,5 +1,5 @@ -import { ButtonProps } from "@/components/button"; +import { ButtonProps } from '@/components/button' -type SheetTriggerProps = ButtonProps; +type SheetTriggerProps = ButtonProps -export type { SheetTriggerProps }; +export type { SheetTriggerProps } diff --git a/src/components/sheet/types/sheet.ts b/src/components/sheet/types/sheet.ts index 76d6e32..200642a 100644 --- a/src/components/sheet/types/sheet.ts +++ b/src/components/sheet/types/sheet.ts @@ -1,15 +1,12 @@ -import { Dialog as SheetPrimitive } from "@radix-ui/react-dialog"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { Dialog as SheetPrimitive } from '@radix-ui/react-dialog' +import { Simplify } from '@/components/_shared/types/simplify' -type SheetPrimitiveProps = Omit< - React.ComponentProps, - "modal" ->; +type SheetPrimitiveProps = Omit, 'modal'> type SheetRenderUIProps = { - isModal?: boolean; -}; + isModal?: boolean +} -type SheetProps = Simplify; +type SheetProps = Simplify -export type { SheetProps }; +export type { SheetProps } diff --git a/src/components/skeleton/components/skeleton.tsx b/src/components/skeleton/components/skeleton.tsx index d9db28c..6be7fd6 100644 --- a/src/components/skeleton/components/skeleton.tsx +++ b/src/components/skeleton/components/skeleton.tsx @@ -1,49 +1,44 @@ -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { SkeletonProps } from "@/components/skeleton/types/skeleton"; -import { getMergedClassName } from "@/components/skeleton/utils/get-merged-class-name"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { SkeletonProps } from '@/components/skeleton/types/skeleton' +import { getMergedClassName } from '@/components/skeleton/utils/get-merged-class-name' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' const Skeleton = (props: SkeletonProps) => { - const { - asChild, - className, - style, - count, - animationDuration, - animationTimingFunction, - variant = "slide", - type = "static", - ...restProps - } = props; + const { + asChild, + className, + style, + count, + animationDuration, + animationTimingFunction, + variant = 'slide', + type = 'static', + ...restProps + } = props - const Component = polymorphic(asChild, "div"); + const Component = polymorphic(asChild, 'div') - const mergedClassName = getMergedClassName(className, variant, type); + const mergedClassName = getMergedClassName(className, variant, type) - const mergedStyle = { - ...style, - ...getAnimationStyleVariables({ - animationDuration, - animationTimingFunction, - defaultAnimationDuration: 1500, - defaultAnimationTimingFunction: "ease", - }), - }; + const mergedStyle = { + ...style, + ...getAnimationStyleVariables({ + animationDuration, + animationTimingFunction, + defaultAnimationDuration: 1500, + defaultAnimationTimingFunction: 'ease', + }), + } - return count ? ( - Array.from({ length: count }, (_, index) => ( - - )) - ) : ( - - ); -}; + return count ? ( + Array.from({ length: count }, (_, index) => ( + + )) + ) : ( + + ) +} -export { Skeleton }; +export { Skeleton } diff --git a/src/components/skeleton/types/skeleton.ts b/src/components/skeleton/types/skeleton.ts index 46180e0..440155b 100644 --- a/src/components/skeleton/types/skeleton.ts +++ b/src/components/skeleton/types/skeleton.ts @@ -1,21 +1,16 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { AnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { AnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' -type SkeletonPrimitiveProps = React.ComponentPropsWithRef<"div">; +type SkeletonPrimitiveProps = React.ComponentPropsWithRef<'div'> type SkeletonRenderCustomProps = { - variant?: "pulse" | "slide"; - type?: "static" | "layer"; - count?: number; -} & Pick< - AnimationStyleVariables, - "animationDuration" | "animationTimingFunction" ->; + variant?: 'pulse' | 'slide' + type?: 'static' | 'layer' + count?: number +} & Pick -type SkeletonProps = Simplify< - SkeletonPrimitiveProps & SkeletonRenderCustomProps & AsChildProp ->; +type SkeletonProps = Simplify -export type { SkeletonProps }; +export type { SkeletonProps } diff --git a/src/components/skeleton/utils/get-merged-class-name.ts b/src/components/skeleton/utils/get-merged-class-name.ts index 1a1c93a..0f1cb91 100644 --- a/src/components/skeleton/utils/get-merged-class-name.ts +++ b/src/components/skeleton/utils/get-merged-class-name.ts @@ -3,18 +3,18 @@ import { cn } from '@renderui/utils' import { SkeletonProps } from '@/components/skeleton/types/skeleton' function getMergedClassName( - className: SkeletonProps['className'], - variant: SkeletonProps['variant'], - type: SkeletonProps['type'], + className: SkeletonProps['className'], + variant: SkeletonProps['variant'], + type: SkeletonProps['type'], ) { - return cn( - 'render-ui-skeletion rounded bg-mode-accent overflow-hidden', - variant === 'pulse' - ? 'animate-[pulse_1500ms_infinite]' - : 'relative isolate w-full before:content-[""] before:absolute before:inline-block before:inset-0 before:z-[1] before:rounded-[inherit] before:animate-slide before:bg-gradient-to-r before:from-transparent before:via-skeleton before:to-transparent', - type === 'layer' ? 'absolute inset-0 size-full rounded-[inherit] overflow-hidden z-[2]' : '', - className, - ) + return cn( + 'render-ui-skeletion rounded bg-mode-accent overflow-hidden', + variant === 'pulse' + ? 'animate-[pulse_1500ms_infinite]' + : 'relative isolate w-full before:content-[""] before:absolute before:inline-block before:inset-0 before:z-[1] before:rounded-[inherit] before:animate-slide before:bg-gradient-to-r before:from-transparent before:via-skeleton before:to-transparent', + type === 'layer' ? 'absolute inset-0 size-full rounded-[inherit] overflow-hidden z-[2]' : '', + className, + ) } export { getMergedClassName } diff --git a/src/components/slider/components/slider-thumb.tsx b/src/components/slider/components/slider-thumb.tsx index 7beabb5..cd106b3 100644 --- a/src/components/slider/components/slider-thumb.tsx +++ b/src/components/slider/components/slider-thumb.tsx @@ -1,22 +1,22 @@ -"use client"; +'use client' -import { SliderThumb as SliderThumbPrimitive } from "@radix-ui/react-slider"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { SliderThumb as SliderThumbPrimitive } from '@radix-ui/react-slider' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_SLIDER_THUMB_CLASSNAME } from "@/components/slider/constants/constants"; -import { SliderThumbProps } from "@/components/slider/types/slider-thumb"; +import { DEFAULT_SLIDER_THUMB_CLASSNAME } from '@/components/slider/constants/constants' +import { SliderThumbProps } from '@/components/slider/types/slider-thumb' const SliderThumb = (props: SliderThumbProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { SliderThumb }; +export { SliderThumb } diff --git a/src/components/slider/components/slider.tsx b/src/components/slider/components/slider.tsx index d55595b..bbebd2a 100644 --- a/src/components/slider/components/slider.tsx +++ b/src/components/slider/components/slider.tsx @@ -1,84 +1,80 @@ -"use client"; +'use client' import { - Slider as SliderPrimitive, - SliderRange as SliderRangePrimitive, - SliderTrack as SliderTrackPrimitive, -} from "@radix-ui/react-slider"; -import { cn, getOptionalObject } from "@renderui/utils"; -import React from "react"; + Slider as SliderPrimitive, + SliderRange as SliderRangePrimitive, + SliderTrack as SliderTrackPrimitive, +} from '@radix-ui/react-slider' +import { cn, getOptionalObject } from '@renderui/utils' +import React from 'react' -import { SliderThumb } from "@/components/slider/components/slider-thumb"; +import { SliderThumb } from '@/components/slider/components/slider-thumb' import { - DEFAULT_SLIDER_CLASSNAME, - DEFAULT_SLIDER_RANGE_CLASSNAME, - DEFAULT_SLIDER_TRACK_CLASSNAME, - HORIZONTAL_SLIDER_CLASSNAME, - HORIZONTAL_SLIDER_TRACK_CLASSNAME, - SLIDER_HORIZONTAL_RANGE_CLASSNAME, - SLIDER_VERTICAL_RANGE_CLASSNAME, - VERTICAL_SLIDER_CLASSNAME, - VERTICAL_SLIDER_TRACK_CLASSNAME, -} from "@/components/slider/constants/constants"; -import { SliderProps } from "@/components/slider/types/slider"; + DEFAULT_SLIDER_CLASSNAME, + DEFAULT_SLIDER_RANGE_CLASSNAME, + DEFAULT_SLIDER_TRACK_CLASSNAME, + HORIZONTAL_SLIDER_CLASSNAME, + HORIZONTAL_SLIDER_TRACK_CLASSNAME, + SLIDER_HORIZONTAL_RANGE_CLASSNAME, + SLIDER_VERTICAL_RANGE_CLASSNAME, + VERTICAL_SLIDER_CLASSNAME, + VERTICAL_SLIDER_TRACK_CLASSNAME, +} from '@/components/slider/constants/constants' +import { SliderProps } from '@/components/slider/types/slider' const Slider = (props: SliderProps) => { - const { - className, - trackProps, - rangeProps, - thumbProps, - children, - isDisabled, - orientation = "horizontal", - ...restProps - } = props; + const { + className, + trackProps, + rangeProps, + thumbProps, + children, + isDisabled, + orientation = 'horizontal', + ...restProps + } = props - const { className: trackClassName, ...restTrackProps } = - getOptionalObject(trackProps); - const { className: rangeClassName, ...restRangeProps } = - getOptionalObject(rangeProps); + const { className: trackClassName, ...restTrackProps } = getOptionalObject(trackProps) + const { className: rangeClassName, ...restRangeProps } = getOptionalObject(rangeProps) - return ( - - - - - {children || } - - ); -}; + return ( + + + + + {children || } + + ) +} -export { Slider }; +export { Slider } diff --git a/src/components/slider/constants/constants.ts b/src/components/slider/constants/constants.ts index 0c9b71e..1d12b5e 100644 --- a/src/components/slider/constants/constants.ts +++ b/src/components/slider/constants/constants.ts @@ -1,12 +1,12 @@ const DEFAULT_SLIDER_CLASSNAME = - 'render-ui-slider group/slider relative flex touch-none select-none items-center data-[disabled]:opacity-40 data-[disabled]:cursor-not-allowed' + 'render-ui-slider group/slider relative flex touch-none select-none items-center data-[disabled]:opacity-40 data-[disabled]:cursor-not-allowed' const HORIZONTAL_SLIDER_CLASSNAME = 'w-full' const VERTICAL_SLIDER_CLASSNAME = 'inline-flex flex-col h-[200px]' const DEFAULT_SLIDER_TRACK_CLASSNAME = - 'render-ui-slider-track relative h-1.5 grow overflow-hidden rounded-full bg-primary/20' + 'render-ui-slider-track relative h-1.5 grow overflow-hidden rounded-full bg-primary/20' const HORIZONTAL_SLIDER_TRACK_CLASSNAME = 'h-1.5 w-full' @@ -19,17 +19,17 @@ const SLIDER_HORIZONTAL_RANGE_CLASSNAME = 'h-full' const SLIDER_VERTICAL_RANGE_CLASSNAME = 'w-full' const DEFAULT_SLIDER_THUMB_CLASSNAME = - 'render-ui-slider-thumb relative block h-4 w-4 rounded-full bg-primary shadow transition-[background-color,box-shadow,border] shadow duration-fast outline-none ring-2 ring-offset-0 ring-ring-color active:ring-ring-color cursor-grab active:cursor-grabbing group-[[data-disabled]]/slider:cursor-not-allowed before:content-[""] before:absolute before:inline-block before:size-[100%] before:left-1/2 before:top-1/2 before:translate-x-[-50%] before:translate-y-[-50%] before:rounded-[inherit] before:bg-mode before:z-[1] active:before:size-[87.5%] before:transition-[background-color,width,height] before:duration-fast focus-visible:ring-2 focus-visible:shadow-[0_0_0_8px_rgba(var(--primary),0.25)]' + 'render-ui-slider-thumb relative block h-4 w-4 rounded-full bg-primary shadow transition-[background-color,box-shadow,border] shadow duration-fast outline-none ring-2 ring-offset-0 ring-ring-color active:ring-ring-color cursor-grab active:cursor-grabbing group-[[data-disabled]]/slider:cursor-not-allowed before:content-[""] before:absolute before:inline-block before:size-[100%] before:left-1/2 before:top-1/2 before:translate-x-[-50%] before:translate-y-[-50%] before:rounded-[inherit] before:bg-mode before:z-[1] active:before:size-[87.5%] before:transition-[background-color,width,height] before:duration-fast focus-visible:ring-2 focus-visible:shadow-[0_0_0_8px_rgba(var(--primary),0.25)]' export { - DEFAULT_SLIDER_CLASSNAME, - DEFAULT_SLIDER_RANGE_CLASSNAME, - DEFAULT_SLIDER_THUMB_CLASSNAME, - DEFAULT_SLIDER_TRACK_CLASSNAME, - HORIZONTAL_SLIDER_CLASSNAME, - HORIZONTAL_SLIDER_TRACK_CLASSNAME, - SLIDER_HORIZONTAL_RANGE_CLASSNAME, - SLIDER_VERTICAL_RANGE_CLASSNAME, - VERTICAL_SLIDER_CLASSNAME, - VERTICAL_SLIDER_TRACK_CLASSNAME, + DEFAULT_SLIDER_CLASSNAME, + DEFAULT_SLIDER_RANGE_CLASSNAME, + DEFAULT_SLIDER_THUMB_CLASSNAME, + DEFAULT_SLIDER_TRACK_CLASSNAME, + HORIZONTAL_SLIDER_CLASSNAME, + HORIZONTAL_SLIDER_TRACK_CLASSNAME, + SLIDER_HORIZONTAL_RANGE_CLASSNAME, + SLIDER_VERTICAL_RANGE_CLASSNAME, + VERTICAL_SLIDER_CLASSNAME, + VERTICAL_SLIDER_TRACK_CLASSNAME, } diff --git a/src/components/slider/index.ts b/src/components/slider/index.ts index 83a68e1..3aae626 100644 --- a/src/components/slider/index.ts +++ b/src/components/slider/index.ts @@ -1,4 +1,4 @@ export * from '@/components/slider/components/slider' -export * from '@/components/slider/components/slider-thumb' +export * from '@/components/slider/components/slider-thumb' export * from '@/components/slider/types/slider' -export * from '@/components/slider/types/slider-thumb' \ No newline at end of file +export * from '@/components/slider/types/slider-thumb' diff --git a/src/components/slider/types/slider-thumb.ts b/src/components/slider/types/slider-thumb.ts index cb1d303..b3ab200 100644 --- a/src/components/slider/types/slider-thumb.ts +++ b/src/components/slider/types/slider-thumb.ts @@ -1,5 +1,5 @@ -import { SliderThumb as SliderThumbPrimitive } from "@radix-ui/react-slider"; +import { SliderThumb as SliderThumbPrimitive } from '@radix-ui/react-slider' -type SliderThumbProps = React.ComponentProps; +type SliderThumbProps = React.ComponentProps -export type { SliderThumbProps }; +export type { SliderThumbProps } diff --git a/src/components/slider/types/slider.ts b/src/components/slider/types/slider.ts index 79aeb28..dbb7a88 100644 --- a/src/components/slider/types/slider.ts +++ b/src/components/slider/types/slider.ts @@ -1,23 +1,20 @@ import { - Slider as SliderPrimitive, - SliderRange as SliderRangePrimitive, - SliderThumb as SliderThumbPrimitive, - SliderTrack as SliderTrackPrimitive, -} from "@radix-ui/react-slider"; -import { Simplify } from "@/components/_shared/types/simplify"; + Slider as SliderPrimitive, + SliderRange as SliderRangePrimitive, + SliderThumb as SliderThumbPrimitive, + SliderTrack as SliderTrackPrimitive, +} from '@radix-ui/react-slider' +import { Simplify } from '@/components/_shared/types/simplify' -type SliderPrimitiveProps = Omit< - React.ComponentProps, - "disabled" ->; +type SliderPrimitiveProps = Omit, 'disabled'> type SliderCustomProps = { - isDisabled?: boolean; - trackProps?: React.ComponentPropsWithRef; - rangeProps?: React.ComponentPropsWithRef; - thumbProps?: React.ComponentPropsWithRef; -}; + isDisabled?: boolean + trackProps?: React.ComponentPropsWithRef + rangeProps?: React.ComponentPropsWithRef + thumbProps?: React.ComponentPropsWithRef +} -type SliderProps = Simplify; +type SliderProps = Simplify -export type { SliderProps }; +export type { SliderProps } diff --git a/src/components/slot/components/slot.tsx b/src/components/slot/components/slot.tsx index 3ae778f..9c316b5 100644 --- a/src/components/slot/components/slot.tsx +++ b/src/components/slot/components/slot.tsx @@ -1 +1 @@ -export { Slot } from "@radix-ui/react-slot"; +export { Slot } from '@radix-ui/react-slot' diff --git a/src/components/sub-layer/components/sub-layer.tsx b/src/components/sub-layer/components/sub-layer.tsx index dbc3c21..f2908d4 100644 --- a/src/components/sub-layer/components/sub-layer.tsx +++ b/src/components/sub-layer/components/sub-layer.tsx @@ -1,23 +1,23 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { DEFAULT_SUB_LAYER_CLASSNAME } from "@/components/sub-layer/constants/constants"; -import { SubLayerProps } from "@/components/sub-layer/types/sub-layer"; +import { DEFAULT_SUB_LAYER_CLASSNAME } from '@/components/sub-layer/constants/constants' +import { SubLayerProps } from '@/components/sub-layer/types/sub-layer' const SubLayer = (props: SubLayerProps) => { - const { asChild, className, role = "presentation", ...restProps } = props; + const { asChild, className, role = 'presentation', ...restProps } = props - const Component = polymorphic(asChild, "span"); + const Component = polymorphic(asChild, 'span') - return ( - - ); -}; + return ( + + ) +} -export { SubLayer }; +export { SubLayer } diff --git a/src/components/sub-layer/constants/constants.ts b/src/components/sub-layer/constants/constants.ts index a49839c..19c8682 100644 --- a/src/components/sub-layer/constants/constants.ts +++ b/src/components/sub-layer/constants/constants.ts @@ -1,4 +1,4 @@ const DEFAULT_SUB_LAYER_CLASSNAME = - "render-ui-sub-layer absolute z-0 inset-0 p-[inherit] rounded-[inherit] overflow-hidden"; + 'render-ui-sub-layer absolute z-0 inset-0 p-[inherit] rounded-[inherit] overflow-hidden' -export { DEFAULT_SUB_LAYER_CLASSNAME }; +export { DEFAULT_SUB_LAYER_CLASSNAME } diff --git a/src/components/sub-layer/types/sub-layer.ts b/src/components/sub-layer/types/sub-layer.ts index 75775df..82be225 100644 --- a/src/components/sub-layer/types/sub-layer.ts +++ b/src/components/sub-layer/types/sub-layer.ts @@ -1,10 +1,8 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type SubLayerProps = Simplify< - React.ComponentPropsWithRef<"span"> & AsChildProp ->; +type SubLayerProps = Simplify & AsChildProp> -export type { SubLayerProps }; +export type { SubLayerProps } diff --git a/src/components/switch/components/switch-thumb.tsx b/src/components/switch/components/switch-thumb.tsx index d9c9107..058548a 100644 --- a/src/components/switch/components/switch-thumb.tsx +++ b/src/components/switch/components/switch-thumb.tsx @@ -1,20 +1,15 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { DEFAULT_SWITCH_THUMB_CLASSNAME } from "@/components/switch/constants/constants"; -import { SwitchThumbProps } from "@/components/switch/types/switch-thumb"; +import { DEFAULT_SWITCH_THUMB_CLASSNAME } from '@/components/switch/constants/constants' +import { SwitchThumbProps } from '@/components/switch/types/switch-thumb' const SwitchThumb = (props: SwitchThumbProps) => { - const { asChild, className, ...restProps } = props; + const { asChild, className, ...restProps } = props - const Component = polymorphic(asChild, "span"); + const Component = polymorphic(asChild, 'span') - return ( - - ); -}; + return +} -export { SwitchThumb }; +export { SwitchThumb } diff --git a/src/components/switch/components/switch.tsx b/src/components/switch/components/switch.tsx index a6c54ef..9d42036 100644 --- a/src/components/switch/components/switch.tsx +++ b/src/components/switch/components/switch.tsx @@ -1,114 +1,103 @@ -"use client"; +'use client' -import { - chain, - cn, - cx, - functionCallOrValue, - getOptionalObject, - polymorphic, -} from "@renderui/utils"; -import React from "react"; +import { chain, cn, cx, functionCallOrValue, getOptionalObject, polymorphic } from '@renderui/utils' +import React from 'react' -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { Button } from "@/components/button"; -import { SwitchThumb } from "@/components/switch/components/switch-thumb"; +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { Button } from '@/components/button' +import { SwitchThumb } from '@/components/switch/components/switch-thumb' import { - DEFAULT_HIDDEN_SWITCH_INPUT_CLASSNAME, - DEFAULT_SWITCH_CLASSNAME, -} from "@/components/switch/constants/constants"; -import { SwitchProps } from "@/components/switch/types/switch"; -import { VisuallyHidden } from "@/components/visually-hidden"; + DEFAULT_HIDDEN_SWITCH_INPUT_CLASSNAME, + DEFAULT_SWITCH_CLASSNAME, +} from '@/components/switch/constants/constants' +import { SwitchProps } from '@/components/switch/types/switch' +import { VisuallyHidden } from '@/components/visually-hidden' const Switch = (props: SwitchProps) => { - const { - inputRef, - inputProps, - name, - className, - defaultChecked, - isChecked: checkedProp, - isDisabled, - isReadOnly, - isInvalid, - isRequired, - startContent, - endContent, - children, - onCheckedChange, - onPress, - role = "switch", - variant = "plain", - color = "primary", - hasRipple = false, - hasDefaultPressedStyles = false, - ...restProps - } = props; + const { + inputRef, + inputProps, + name, + className, + defaultChecked, + isChecked: checkedProp, + isDisabled, + isReadOnly, + isInvalid, + isRequired, + startContent, + endContent, + children, + onCheckedChange, + onPress, + role = 'switch', + variant = 'plain', + color = 'primary', + hasRipple = false, + hasDefaultPressedStyles = false, + ...restProps + } = props - const [checked, setChecked] = useControllableState({ - prop: checkedProp, - defaultProp: defaultChecked, - onChange: onCheckedChange, - }); + const [checked, setChecked] = useControllableState({ + prop: checkedProp, + defaultProp: defaultChecked, + onChange: onCheckedChange, + }) - const { - asChild, - name: inputName, - value: inputValue, - className: inputClassName, - checked: inputChecked, - onChange, - ...restInputProps - } = getOptionalObject(inputProps); + const { + asChild, + name: inputName, + value: inputValue, + className: inputClassName, + checked: inputChecked, + onChange, + ...restInputProps + } = getOptionalObject(inputProps) - const InputComponent = polymorphic(asChild, "input"); + const InputComponent = polymorphic(asChild, 'input') - return ( - - ); -}; + return ( + + ) +} -export { Switch }; +export { Switch } diff --git a/src/components/switch/constants/constants.ts b/src/components/switch/constants/constants.ts index c5db385..3eac6aa 100644 --- a/src/components/switch/constants/constants.ts +++ b/src/components/switch/constants/constants.ts @@ -1,13 +1,13 @@ const DEFAULT_SWITCH_CLASSNAME = - 'render-ui-switch group px-1 relative inline-flex items-center justify-start shrink-0 overflow-hidden bg-mode-accent rounded-full data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground w-12 h-7 transition-background' + 'render-ui-switch group px-1 relative inline-flex items-center justify-start shrink-0 overflow-hidden bg-mode-accent rounded-full data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground w-12 h-7 transition-background' const DEFAULT_SWITCH_THUMB_CLASSNAME = - 'render-ui-switch-thumb relative z-[1] pointer-events-none flex items-center justify-center rounded-full bg-white transition-all duration-fast-medium w-5 h-5 group-data-[state=checked]:ml-5 group-data-[pressed=true]:w-6 group-data-[state=checked]:group-data-[pressed=true]:ml-4' + 'render-ui-switch-thumb relative z-[1] pointer-events-none flex items-center justify-center rounded-full bg-white transition-all duration-fast-medium w-5 h-5 group-data-[state=checked]:ml-5 group-data-[pressed=true]:w-6 group-data-[state=checked]:group-data-[pressed=true]:ml-4' const DEFAULT_HIDDEN_SWITCH_INPUT_CLASSNAME = 'render-ui-switch-hidden-input' export { - DEFAULT_HIDDEN_SWITCH_INPUT_CLASSNAME, - DEFAULT_SWITCH_CLASSNAME, - DEFAULT_SWITCH_THUMB_CLASSNAME, + DEFAULT_HIDDEN_SWITCH_INPUT_CLASSNAME, + DEFAULT_SWITCH_CLASSNAME, + DEFAULT_SWITCH_THUMB_CLASSNAME, } diff --git a/src/components/switch/types/switch-thumb.ts b/src/components/switch/types/switch-thumb.ts index 8841514..4b869b4 100644 --- a/src/components/switch/types/switch-thumb.ts +++ b/src/components/switch/types/switch-thumb.ts @@ -1,10 +1,8 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; +import { AsChildProp } from '@/components/_shared/types/as-child' -type SwitchThumbProps = Simplify< - React.ComponentPropsWithRef<"span"> & AsChildProp ->; +type SwitchThumbProps = Simplify & AsChildProp> -export type { SwitchThumbProps }; +export type { SwitchThumbProps } diff --git a/src/components/switch/types/switch.ts b/src/components/switch/types/switch.ts index d3bafd4..bfa5308 100644 --- a/src/components/switch/types/switch.ts +++ b/src/components/switch/types/switch.ts @@ -1,39 +1,31 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { ButtonProps } from "@/components/button"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { ButtonProps } from '@/components/button' type SwitchButtonProps = Omit< - ButtonProps, - | "children" - | "disabled" - | "readonly" - | "required" - | "startContent" - | "children" - | "endContent" ->; + ButtonProps, + 'children' | 'disabled' | 'readonly' | 'required' | 'startContent' | 'children' | 'endContent' +> type SwitchCustomProps = { - startContent?: React.ReactNode | ((checked: boolean) => React.ReactNode); - children?: React.ReactNode | ((checked: boolean) => React.ReactNode); - endContent?: React.ReactNode | ((checked: boolean) => React.ReactNode); - inputRef?: React.Ref; - inputProps?: Simplify< - React.InputHTMLAttributes & AsChildProp - >; - name?: string; - defaultChecked?: boolean; - isChecked?: boolean; - isDisabled?: boolean; - isReadOnly?: boolean; - isInvalid?: boolean; - isRequired?: boolean; - hasDefaultPressedStyles?: boolean; - onCheckedChange?: (checked: boolean) => void; - onPress?: (event: React.MouseEvent) => void; -}; + startContent?: React.ReactNode | ((checked: boolean) => React.ReactNode) + children?: React.ReactNode | ((checked: boolean) => React.ReactNode) + endContent?: React.ReactNode | ((checked: boolean) => React.ReactNode) + inputRef?: React.Ref + inputProps?: Simplify & AsChildProp> + name?: string + defaultChecked?: boolean + isChecked?: boolean + isDisabled?: boolean + isReadOnly?: boolean + isInvalid?: boolean + isRequired?: boolean + hasDefaultPressedStyles?: boolean + onCheckedChange?: (checked: boolean) => void + onPress?: (event: React.MouseEvent) => void +} -type SwitchProps = Simplify; +type SwitchProps = Simplify -export type { SwitchProps }; +export type { SwitchProps } diff --git a/src/components/tabs/classes/shared.ts b/src/components/tabs/classes/shared.ts index 8bf8825..43b7c48 100644 --- a/src/components/tabs/classes/shared.ts +++ b/src/components/tabs/classes/shared.ts @@ -1,17 +1,17 @@ const TABS_SHARED_ORIENTATIONS = { - horizontal: '', - vertical: '', + horizontal: '', + vertical: '', } as const const TABS_SHARED_VARIANTS = { - 'solid': '', - 'outline': '', - 'lined': '', - 'lined-track': '', - 'lined-reverse': '', - 'lined-track-reverse': '', - 'card': '', - 'card-reverse': '', + 'solid': '', + 'outline': '', + 'lined': '', + 'lined-track': '', + 'lined-reverse': '', + 'lined-track-reverse': '', + 'card': '', + 'card-reverse': '', } as const export { TABS_SHARED_ORIENTATIONS, TABS_SHARED_VARIANTS } diff --git a/src/components/tabs/classes/tabs-cursor-classes.ts b/src/components/tabs/classes/tabs-cursor-classes.ts index def6716..651a1c9 100644 --- a/src/components/tabs/classes/tabs-cursor-classes.ts +++ b/src/components/tabs/classes/tabs-cursor-classes.ts @@ -3,62 +3,62 @@ import { cva } from '@renderui/utils' import { TABS_SHARED_ORIENTATIONS, TABS_SHARED_VARIANTS } from '@/components/tabs/classes/shared' const tabsCursorClasses = cva('render-ui-tabs-cursor absolute inset-0 z-[1] size-full rounded', { - variants: { - variant: TABS_SHARED_VARIANTS, - orientation: TABS_SHARED_ORIENTATIONS, - }, - compoundVariants: [ - { - variant: ['lined', 'lined-track'], - orientation: 'horizontal', - className: 'inset-x-0 bottom-0 top-auto', - }, - { - variant: ['lined-reverse', 'lined-track-reverse'], - orientation: 'horizontal', - className: 'inset-x-0 bottom-auto top-0', - }, - { - variant: ['lined', 'lined-track'], - orientation: 'vertical', - className: 'inset-y-0 left-0 right-auto', - }, - { - variant: ['lined-reverse', 'lined-track-reverse'], - orientation: 'vertical', - className: 'inset-y-0 left-auto right-0', - }, - { - variant: ['lined', 'lined-track', 'lined-reverse', 'lined-track-reverse'], - orientation: 'horizontal', - className: 'h-[2px] w-full', - }, - { - variant: ['lined', 'lined-track', 'lined-reverse', 'lined-track-reverse'], - orientation: 'vertical', - className: 'h-full w-[2px]', - }, - { - orientation: 'horizontal', - variant: 'card', - className: 'rounded-b-none', - }, - { - orientation: 'horizontal', - variant: 'card-reverse', - className: 'rounded-t-none', - }, - { - orientation: 'vertical', - variant: 'card', - className: 'rounded-l-none', - }, - { - orientation: 'vertical', - variant: 'card-reverse', - className: 'rounded-r-none', - }, - ], + variants: { + variant: TABS_SHARED_VARIANTS, + orientation: TABS_SHARED_ORIENTATIONS, + }, + compoundVariants: [ + { + variant: ['lined', 'lined-track'], + orientation: 'horizontal', + className: 'inset-x-0 bottom-0 top-auto', + }, + { + variant: ['lined-reverse', 'lined-track-reverse'], + orientation: 'horizontal', + className: 'inset-x-0 bottom-auto top-0', + }, + { + variant: ['lined', 'lined-track'], + orientation: 'vertical', + className: 'inset-y-0 left-0 right-auto', + }, + { + variant: ['lined-reverse', 'lined-track-reverse'], + orientation: 'vertical', + className: 'inset-y-0 left-auto right-0', + }, + { + variant: ['lined', 'lined-track', 'lined-reverse', 'lined-track-reverse'], + orientation: 'horizontal', + className: 'h-[2px] w-full', + }, + { + variant: ['lined', 'lined-track', 'lined-reverse', 'lined-track-reverse'], + orientation: 'vertical', + className: 'h-full w-[2px]', + }, + { + orientation: 'horizontal', + variant: 'card', + className: 'rounded-b-none', + }, + { + orientation: 'horizontal', + variant: 'card-reverse', + className: 'rounded-t-none', + }, + { + orientation: 'vertical', + variant: 'card', + className: 'rounded-l-none', + }, + { + orientation: 'vertical', + variant: 'card-reverse', + className: 'rounded-r-none', + }, + ], }) export { tabsCursorClasses } diff --git a/src/components/tabs/classes/tabs-trigger-list-classes.ts b/src/components/tabs/classes/tabs-trigger-list-classes.ts index e27d2e8..b3f0b13 100644 --- a/src/components/tabs/classes/tabs-trigger-list-classes.ts +++ b/src/components/tabs/classes/tabs-trigger-list-classes.ts @@ -3,127 +3,127 @@ import { cva } from '@renderui/utils' import { TABS_SHARED_ORIENTATIONS, TABS_SHARED_VARIANTS } from '@/components/tabs/classes/shared' const tabsTriggerListClasses = cva( - 'render-ui-trigger-list flex w-fit rounded p-1 transition-[background-color,border-color] duration-fast', - { - variants: { - variant: TABS_SHARED_VARIANTS, - orientation: TABS_SHARED_ORIENTATIONS, - }, - compoundVariants: [ - { - orientation: ['horizontal'], - className: 'flex grow-children', - }, - { - orientation: ['vertical'], - className: 'flex-col', - }, - { - variant: ['solid'], - className: 'bg-mode-accent', - }, - { - variant: 'outline', - className: 'border-2', - }, - { - variant: [ - 'lined', - 'lined-track', - 'lined-reverse', - 'lined-track-reverse', - 'outline', - 'card', - 'card-reverse', - ], - className: 'bg-transparent', - }, - { - orientation: 'horizontal', - variant: 'card', - className: 'rounded-b-none border-b-2', - }, - { - orientation: 'horizontal', - variant: 'card-reverse', - className: 'rounded-t-none border-t-2', - }, - { - orientation: 'vertical', - variant: 'card', - className: 'rounded-l-none border-l-2', - }, - { - orientation: 'vertical', - variant: ['card-reverse'], - className: ['rounded-r-none', 'border-r-2'], - }, - { - variant: ['outline', 'card', 'card-reverse'], - className: 'border-mode-accent', - }, - { - orientation: 'horizontal', - variant: ['card', 'card-reverse'], - className: 'rounded-none', - }, - { - orientation: 'vertical', - variant: ['card', 'card-reverse'], - className: 'rounded-none', - }, - { - orientation: 'horizontal', - variant: ['card', 'card-reverse'], - className: 'rounded-none', - }, - { - variant: [ - 'solid', - 'outline', - 'lined', - 'lined-track', - 'lined-reverse', - 'lined-track-reverse', - ], - className: ['items-center justify-center gap-2 rounded p-1'], - }, - { - orientation: 'horizontal', - variant: ['card', 'card-reverse'], - className: 'overflow-y-clip overflow-x-visible p-0', - }, - { - orientation: 'vertical', - variant: ['card', 'card-reverse'], - className: 'overflow-x-clip overflow-y-visible p-0', - }, - { - orientation: 'horizontal', - variant: ['lined-track'], - className: - 'relative before:absolute before:inset-x-0 before:bottom-[4px] before:top-auto before:z-0 before:mx-auto before:h-[2px] before:w-[calc(100%_-_0.5rem)] before:rounded-small before:bg-mode-accent before:content-[""]', - }, - { - orientation: 'horizontal', - variant: ['lined-track-reverse'], - className: - 'relative before:absolute before:inset-x-0 before:bottom-auto before:top-[4px] before:z-0 before:mx-auto before:h-[2px] before:w-[calc(100%_-_0.5rem)] before:rounded-small before:bg-mode-accent before:content-[""]', - }, - { - orientation: 'vertical', - variant: ['lined-track'], - className: - 'relative before:absolute before:inset-0 before:left-[4px] before:right-auto before:z-0 before:my-auto before:h-[calc(100%_-_0.5rem)] before:w-[2px] before:rounded-small before:bg-mode-accent before:content-[""]', - }, - { - orientation: 'vertical', - variant: ['lined-track-reverse'], - className: - 'relative before:absolute before:inset-0 before:left-auto before:right-[4px] before:z-0 before:my-auto before:h-[calc(100%_-_0.5rem)] before:w-[2px] before:rounded-small before:bg-mode-accent before:content-[""]', - }, - ], - }, + 'render-ui-trigger-list flex w-fit rounded p-1 transition-[background-color,border-color] duration-fast', + { + variants: { + variant: TABS_SHARED_VARIANTS, + orientation: TABS_SHARED_ORIENTATIONS, + }, + compoundVariants: [ + { + orientation: ['horizontal'], + className: 'flex grow-children', + }, + { + orientation: ['vertical'], + className: 'flex-col', + }, + { + variant: ['solid'], + className: 'bg-mode-accent', + }, + { + variant: 'outline', + className: 'border-2', + }, + { + variant: [ + 'lined', + 'lined-track', + 'lined-reverse', + 'lined-track-reverse', + 'outline', + 'card', + 'card-reverse', + ], + className: 'bg-transparent', + }, + { + orientation: 'horizontal', + variant: 'card', + className: 'rounded-b-none border-b-2', + }, + { + orientation: 'horizontal', + variant: 'card-reverse', + className: 'rounded-t-none border-t-2', + }, + { + orientation: 'vertical', + variant: 'card', + className: 'rounded-l-none border-l-2', + }, + { + orientation: 'vertical', + variant: ['card-reverse'], + className: ['rounded-r-none', 'border-r-2'], + }, + { + variant: ['outline', 'card', 'card-reverse'], + className: 'border-mode-accent', + }, + { + orientation: 'horizontal', + variant: ['card', 'card-reverse'], + className: 'rounded-none', + }, + { + orientation: 'vertical', + variant: ['card', 'card-reverse'], + className: 'rounded-none', + }, + { + orientation: 'horizontal', + variant: ['card', 'card-reverse'], + className: 'rounded-none', + }, + { + variant: [ + 'solid', + 'outline', + 'lined', + 'lined-track', + 'lined-reverse', + 'lined-track-reverse', + ], + className: ['items-center justify-center gap-2 rounded p-1'], + }, + { + orientation: 'horizontal', + variant: ['card', 'card-reverse'], + className: 'overflow-y-clip overflow-x-visible p-0', + }, + { + orientation: 'vertical', + variant: ['card', 'card-reverse'], + className: 'overflow-x-clip overflow-y-visible p-0', + }, + { + orientation: 'horizontal', + variant: ['lined-track'], + className: + 'relative before:absolute before:inset-x-0 before:bottom-[4px] before:top-auto before:z-0 before:mx-auto before:h-[2px] before:w-[calc(100%_-_0.5rem)] before:rounded-small before:bg-mode-accent before:content-[""]', + }, + { + orientation: 'horizontal', + variant: ['lined-track-reverse'], + className: + 'relative before:absolute before:inset-x-0 before:bottom-auto before:top-[4px] before:z-0 before:mx-auto before:h-[2px] before:w-[calc(100%_-_0.5rem)] before:rounded-small before:bg-mode-accent before:content-[""]', + }, + { + orientation: 'vertical', + variant: ['lined-track'], + className: + 'relative before:absolute before:inset-0 before:left-[4px] before:right-auto before:z-0 before:my-auto before:h-[calc(100%_-_0.5rem)] before:w-[2px] before:rounded-small before:bg-mode-accent before:content-[""]', + }, + { + orientation: 'vertical', + variant: ['lined-track-reverse'], + className: + 'relative before:absolute before:inset-0 before:left-auto before:right-[4px] before:z-0 before:my-auto before:h-[calc(100%_-_0.5rem)] before:w-[2px] before:rounded-small before:bg-mode-accent before:content-[""]', + }, + ], + }, ) export { tabsTriggerListClasses } diff --git a/src/components/tabs/components/tabs-content.tsx b/src/components/tabs/components/tabs-content.tsx index 71c6d87..dcfeeb4 100644 --- a/src/components/tabs/components/tabs-content.tsx +++ b/src/components/tabs/components/tabs-content.tsx @@ -1,22 +1,22 @@ -"use client"; +'use client' -import { TabsContent as TabsContentPrimitive } from "@radix-ui/react-tabs"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { TabsContent as TabsContentPrimitive } from '@radix-ui/react-tabs' +import { cn } from '@renderui/utils' +import React from 'react' -import { DEFAULT_TABS_CONTENT_CLASSNAME } from "@/components/tabs/constants/constants"; -import { TabsContentProps } from "@/components/tabs/types/tabs-content"; +import { DEFAULT_TABS_CONTENT_CLASSNAME } from '@/components/tabs/constants/constants' +import { TabsContentProps } from '@/components/tabs/types/tabs-content' const TabsContent = (props: TabsContentProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - return ( - - ); -}; + return ( + + ) +} -export { TabsContent }; +export { TabsContent } diff --git a/src/components/tabs/components/tabs-cursor.tsx b/src/components/tabs/components/tabs-cursor.tsx index 2495ca0..d89c518 100644 --- a/src/components/tabs/components/tabs-cursor.tsx +++ b/src/components/tabs/components/tabs-cursor.tsx @@ -1,63 +1,50 @@ -"use client"; +'use client' -import { cn } from "@renderui/utils"; -import { m } from "framer-motion"; -import React from "react"; +import { cn } from '@renderui/utils' +import { m } from 'framer-motion' +import React from 'react' -import { buttonClasses } from "@/components/button/classes/button-classes"; -import { tabsCursorClasses } from "@/components/tabs/classes/tabs-cursor-classes"; -import { DEFAULT_TABS_CURSOR_CLASSNAME } from "@/components/tabs/constants/constants"; -import { useTabsContext } from "@/components/tabs/context/tabs-context"; -import { TabsCursorProps } from "@/components/tabs/types/tabs-cursor"; -import { getMergedCursorTransition } from "@/components/tabs/utils/get-merged-cursor-transition"; +import { buttonClasses } from '@/components/button/classes/button-classes' +import { tabsCursorClasses } from '@/components/tabs/classes/tabs-cursor-classes' +import { DEFAULT_TABS_CURSOR_CLASSNAME } from '@/components/tabs/constants/constants' +import { useTabsContext } from '@/components/tabs/context/tabs-context' +import { TabsCursorProps } from '@/components/tabs/types/tabs-cursor' +import { getMergedCursorTransition } from '@/components/tabs/utils/get-merged-cursor-transition' const TabsCursor = (props: TabsCursorProps) => { - const { className, transition, initial, animate, ...restProps } = props; + const { className, transition, initial, animate, ...restProps } = props - const { - layoutId, - orientation, - variant, - animationDuration, - hasCursorAppearedRef, - } = useTabsContext(); + const { layoutId, orientation, variant, animationDuration, hasCursorAppearedRef } = + useTabsContext() - React.useEffect(() => { - hasCursorAppearedRef.current = true; - // disabling rule, linter not recognizing ref - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + React.useEffect(() => { + hasCursorAppearedRef.current = true + // disabling rule, linter not recognizing ref + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) - return ( - - ); -}; + return ( + + ) +} -export { TabsCursor }; +export { TabsCursor } diff --git a/src/components/tabs/components/tabs-trigger-children-container.tsx b/src/components/tabs/components/tabs-trigger-children-container.tsx index 32385d8..984b9df 100644 --- a/src/components/tabs/components/tabs-trigger-children-container.tsx +++ b/src/components/tabs/components/tabs-trigger-children-container.tsx @@ -1,30 +1,25 @@ -import { DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME } from "@/components/tabs/constants/constants"; -import { TabsTriggerChildrenContainerProps } from "@/components/tabs/types/tabs-trigger-children-container"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME } from '@/components/tabs/constants/constants' +import { TabsTriggerChildrenContainerProps } from '@/components/tabs/types/tabs-trigger-children-container' +import { cn } from '@renderui/utils' +import React from 'react' -const TabsTriggerChildrenContainer = ( - props: TabsTriggerChildrenContainerProps -) => { - const { className, children, ...restProps } = props; +const TabsTriggerChildrenContainer = (props: TabsTriggerChildrenContainerProps) => { + const { className, children, ...restProps } = props - return ( - <> - - {children} - - - {children} - - - ); -}; + return ( + <> + + {children} + + + {children} + + + ) +} -export { TabsTriggerChildrenContainer }; +export { TabsTriggerChildrenContainer } diff --git a/src/components/tabs/components/tabs-trigger-list.tsx b/src/components/tabs/components/tabs-trigger-list.tsx index 1b883de..92a51c6 100644 --- a/src/components/tabs/components/tabs-trigger-list.tsx +++ b/src/components/tabs/components/tabs-trigger-list.tsx @@ -1,28 +1,25 @@ -"use client"; +'use client' -import { TabsList as TabsTriggerListPrimitive } from "@radix-ui/react-tabs"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { TabsList as TabsTriggerListPrimitive } from '@radix-ui/react-tabs' +import { cn } from '@renderui/utils' +import React from 'react' -import { tabsTriggerListClasses } from "@/components/tabs/classes/tabs-trigger-list-classes"; -import { useTabsContext } from "@/components/tabs/context/tabs-context"; -import { TabsTriggerListProps } from "@/components/tabs/types/tabs-trigger-list"; +import { tabsTriggerListClasses } from '@/components/tabs/classes/tabs-trigger-list-classes' +import { useTabsContext } from '@/components/tabs/context/tabs-context' +import { TabsTriggerListProps } from '@/components/tabs/types/tabs-trigger-list' const TabsTriggerList = (props: TabsTriggerListProps) => { - const { className, ...restProps } = props; + const { className, ...restProps } = props - const { orientation, variant } = useTabsContext(); + const { orientation, variant } = useTabsContext() - return ( - - ); -}; + return ( + + ) +} -export { TabsTriggerList }; +export { TabsTriggerList } diff --git a/src/components/tabs/components/tabs-trigger.tsx b/src/components/tabs/components/tabs-trigger.tsx index dbaeede..2a93cbc 100644 --- a/src/components/tabs/components/tabs-trigger.tsx +++ b/src/components/tabs/components/tabs-trigger.tsx @@ -1,105 +1,103 @@ -"use client"; +'use client' -import { TabsTrigger as TabsTriggerPrimitive } from "@radix-ui/react-tabs"; -import { cx, functionCallOrValue, getOptionalObject } from "@renderui/utils"; -import React from "react"; -import { chain } from "react-aria"; +import { TabsTrigger as TabsTriggerPrimitive } from '@radix-ui/react-tabs' +import { cx, functionCallOrValue, getOptionalObject } from '@renderui/utils' +import React from 'react' +import { chain } from 'react-aria' -import { Button } from "@/components/button"; -import { TabsCursor } from "@/components/tabs/components/tabs-cursor"; -import { TabsTriggerChildrenContainer } from "@/components/tabs/components/tabs-trigger-children-container"; +import { Button } from '@/components/button' +import { TabsCursor } from '@/components/tabs/components/tabs-cursor' +import { TabsTriggerChildrenContainer } from '@/components/tabs/components/tabs-trigger-children-container' import { - DEFAULT_TABS_TRIGGER_CLASSNAME, - INACTIVE_TABS_TRIGGER_CLASSNAME, - NO_BORDER_RADIUS_ON_TRIGGER_VARIANTS, - NO_BORDER_RADIUS_TABS_TRIGGER_CLASSNAME, -} from "@/components/tabs/constants/constants"; -import { useTabsContext } from "@/components/tabs/context/tabs-context"; -import { TabsTriggerProps } from "@/components/tabs/types/tabs-trigger"; -import { getHandleTriggerPress } from "@/components/tabs/utils/get-handdle-trigger-press"; + DEFAULT_TABS_TRIGGER_CLASSNAME, + INACTIVE_TABS_TRIGGER_CLASSNAME, + NO_BORDER_RADIUS_ON_TRIGGER_VARIANTS, + NO_BORDER_RADIUS_TABS_TRIGGER_CLASSNAME, +} from '@/components/tabs/constants/constants' +import { useTabsContext } from '@/components/tabs/context/tabs-context' +import { TabsTriggerProps } from '@/components/tabs/types/tabs-trigger' +import { getHandleTriggerPress } from '@/components/tabs/utils/get-handdle-trigger-press' const TabsTrigger = (props: TabsTriggerProps) => { - const { - asChild, - value, - className, - children, - color, - isDisabled, - childrenContainerProps, - onPress, - variant = "solid", - hasRipple = false, - hasDefaultHoverStyles = false, - hasDefaultPressedStyles = false, - ...restProps - } = props; + const { + asChild, + value, + className, + children, + color, + isDisabled, + childrenContainerProps, + onPress, + variant = 'solid', + hasRipple = false, + hasDefaultHoverStyles = false, + hasDefaultPressedStyles = false, + ...restProps + } = props - const { - className: childrenContainerClassName, - ...restChildrenContainerProps - } = getOptionalObject(childrenContainerProps); + const { className: childrenContainerClassName, ...restChildrenContainerProps } = + getOptionalObject(childrenContainerProps) - const { - activeTab, - color: rootColor, - variant: rootVariant, - type, - hasCursor, - setActiveTab, - } = useTabsContext(); + const { + activeTab, + color: rootColor, + variant: rootVariant, + type, + hasCursor, + setActiveTab, + } = useTabsContext() - const isSelected = activeTab === value; + const isSelected = activeTab === value - return ( - - - - ); -}; + return ( + + + + ) +} -export { TabsTrigger }; +export { TabsTrigger } diff --git a/src/components/tabs/components/tabs.tsx b/src/components/tabs/components/tabs.tsx index 2c5b180..42b83f9 100644 --- a/src/components/tabs/components/tabs.tsx +++ b/src/components/tabs/components/tabs.tsx @@ -1,69 +1,69 @@ -"use client"; +'use client' -import { Tabs as TabsPrimitive } from "@radix-ui/react-tabs"; -import { cn } from "@renderui/utils"; -import React from "react"; +import { Tabs as TabsPrimitive } from '@radix-ui/react-tabs' +import { cn } from '@renderui/utils' +import React from 'react' -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { DEFAULT_TABS_CLASSNAME } from "@/components/tabs/constants/constants"; -import { TabsProvider } from "@/components/tabs/context/tabs-context"; -import { TabsProps } from "@/components/tabs/types/tabs"; -import { LazyMotionDomMaxProvider } from "@/providers"; +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { DEFAULT_TABS_CLASSNAME } from '@/components/tabs/constants/constants' +import { TabsProvider } from '@/components/tabs/context/tabs-context' +import { TabsProps } from '@/components/tabs/types/tabs' +import { LazyMotionDomMaxProvider } from '@/providers' const Tabs = (props: TabsProps) => { - const { - onValueChange, - defaultValue, - value, - className, - children, - animationDuration, - type = "click", - color = "primary", - variant = "outline", - orientation = "horizontal", - hasCursor = true, - ...restProps - } = props; + const { + onValueChange, + defaultValue, + value, + className, + children, + animationDuration, + type = 'click', + color = 'primary', + variant = 'outline', + orientation = 'horizontal', + hasCursor = true, + ...restProps + } = props - const layoutId = React.useId(); + const layoutId = React.useId() - const [activeTab, setActiveTab] = useControllableState({ - prop: value, - defaultProp: defaultValue, - onChange: onValueChange, - }); + const [activeTab, setActiveTab] = useControllableState({ + prop: value, + defaultProp: defaultValue, + onChange: onValueChange, + }) - const hasCursorAppearedRef = React.useRef(false); + const hasCursorAppearedRef = React.useRef(false) - return ( - - - {children} - - - ); -}; + return ( + + + {children} + + + ) +} -export { Tabs }; +export { Tabs } diff --git a/src/components/tabs/constants/constants.ts b/src/components/tabs/constants/constants.ts index aef135d..bb2b513 100644 --- a/src/components/tabs/constants/constants.ts +++ b/src/components/tabs/constants/constants.ts @@ -2,48 +2,48 @@ import { NonNullableVariantProps } from '@/components/_shared/types/variants' import { tabsCursorClasses } from '@/components/tabs/classes/tabs-cursor-classes' const DEFAULT_TABS_CURSOR_TRANISTION = { - type: 'spring', - bounce: 0, - duration: 0.35, + type: 'spring', + bounce: 0, + duration: 0.35, } as const const DEFAULT_TABS_CLASSNAME = 'render-ui-tabs' const DEFAULT_TABS_TRIGGER_CLASSNAME = - 'render-ui-tabs-trigger bg-transparent before:hidden after:hidden' + 'render-ui-tabs-trigger bg-transparent before:hidden after:hidden' const DEFAULT_TABS_CONTENT_CLASSNAME = - 'render-ui-tabs-content outline-none ring-ring-color ring-offset-background focus-visible:ring-ring-width focus-visible:ring-offset-offset transition-colors duration-fast' + 'render-ui-tabs-content outline-none ring-ring-color ring-offset-background focus-visible:ring-ring-width focus-visible:ring-offset-offset transition-colors duration-fast' const DEFAULT_TABS_CURSOR_CLASSNAME = 'transition-none' const NO_BORDER_RADIUS_ON_TRIGGER_VARIANTS: Partial< - NonNullableVariantProps['variant'] + NonNullableVariantProps['variant'] >[] = [ - 'card', - 'card-reverse', - 'lined', - 'lined-reverse', - 'lined-track', - 'lined-track-reverse', + 'card', + 'card-reverse', + 'lined', + 'lined-reverse', + 'lined-track', + 'lined-track-reverse', ] as const const NO_BORDER_RADIUS_TABS_TRIGGER_CLASSNAME = 'rounded-none' const INACTIVE_TABS_TRIGGER_CLASSNAME = - 'text-mode-contrast transition-[color] duration-fast data-[hover="true"]:data-[state="inactive"]:text-primary' + 'text-mode-contrast transition-[color] duration-fast data-[hover="true"]:data-[state="inactive"]:text-primary' const DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME = - 'absolute inset-0 z-[2] flex size-full items-center justify-center gap-3 text-[inherit]' + 'absolute inset-0 z-[2] flex size-full items-center justify-center gap-3 text-[inherit]' export { - DEFAULT_TABS_CLASSNAME, - DEFAULT_TABS_CONTENT_CLASSNAME, - DEFAULT_TABS_CURSOR_CLASSNAME, - DEFAULT_TABS_CURSOR_TRANISTION, - DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME, - DEFAULT_TABS_TRIGGER_CLASSNAME, - INACTIVE_TABS_TRIGGER_CLASSNAME, - NO_BORDER_RADIUS_ON_TRIGGER_VARIANTS, - NO_BORDER_RADIUS_TABS_TRIGGER_CLASSNAME, + DEFAULT_TABS_CLASSNAME, + DEFAULT_TABS_CONTENT_CLASSNAME, + DEFAULT_TABS_CURSOR_CLASSNAME, + DEFAULT_TABS_CURSOR_TRANISTION, + DEFAULT_TABS_TRIGGER_CHILDREN_CONTAINER_CLASSNAME, + DEFAULT_TABS_TRIGGER_CLASSNAME, + INACTIVE_TABS_TRIGGER_CLASSNAME, + NO_BORDER_RADIUS_ON_TRIGGER_VARIANTS, + NO_BORDER_RADIUS_TABS_TRIGGER_CLASSNAME, } diff --git a/src/components/tabs/context/tabs-context.ts b/src/components/tabs/context/tabs-context.ts index f56ab56..f062fc3 100644 --- a/src/components/tabs/context/tabs-context.ts +++ b/src/components/tabs/context/tabs-context.ts @@ -3,11 +3,11 @@ import { initializeContext } from '@renderui/utils' import { TabsContext } from '@/components/tabs/types/tabs-context' const [TabsProvider, useTabsContext] = initializeContext({ - errorMessage: 'Components using useTabsContext must be wrapped in a component.', - providerName: 'TabsProvider', - hookName: 'useTabsContext', - name: 'TabsContext', - strict: true, + errorMessage: 'Components using useTabsContext must be wrapped in a component.', + providerName: 'TabsProvider', + hookName: 'useTabsContext', + name: 'TabsContext', + strict: true, }) export { TabsProvider, useTabsContext } diff --git a/src/components/tabs/types/tabs-content.ts b/src/components/tabs/types/tabs-content.ts index afcdabd..713e5aa 100644 --- a/src/components/tabs/types/tabs-content.ts +++ b/src/components/tabs/types/tabs-content.ts @@ -1,10 +1,10 @@ -import { TabsContent as TabsContentPrimitive } from "@radix-ui/react-tabs"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { TabsContent as TabsContentPrimitive } from '@radix-ui/react-tabs' +import { Simplify } from '@/components/_shared/types/simplify' -type TabsContentPrimtiiveType = typeof TabsContentPrimitive; +type TabsContentPrimtiiveType = typeof TabsContentPrimitive -type TabsContentPrimitiveProps = React.ComponentProps; +type TabsContentPrimitiveProps = React.ComponentProps -type TabsContentProps = Simplify; +type TabsContentProps = Simplify -export type { TabsContentProps }; +export type { TabsContentProps } diff --git a/src/components/tabs/types/tabs-context.ts b/src/components/tabs/types/tabs-context.ts index e9f0ee8..b8c71cd 100644 --- a/src/components/tabs/types/tabs-context.ts +++ b/src/components/tabs/types/tabs-context.ts @@ -1,19 +1,19 @@ -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { ButtonProps } from "@/components/button"; -import { tabsCursorClasses } from "@/components/tabs/classes/tabs-cursor-classes"; -import { TabsProps } from "@/components/tabs/types/tabs"; +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { ButtonProps } from '@/components/button' +import { tabsCursorClasses } from '@/components/tabs/classes/tabs-cursor-classes' +import { TabsProps } from '@/components/tabs/types/tabs' type TabsContext = { - activeTab: string | number; - layoutId: string; - orientation: TabsProps["orientation"]; - variant: NonNullableVariantProps["variant"]; - color: ButtonProps["color"]; - type: TabsProps["type"]; - animationDuration: number | undefined; - hasCursor: boolean; - hasCursorAppearedRef: React.RefObject; - setActiveTab: React.Dispatch>; -}; + activeTab: string | number + layoutId: string + orientation: TabsProps['orientation'] + variant: NonNullableVariantProps['variant'] + color: ButtonProps['color'] + type: TabsProps['type'] + animationDuration: number | undefined + hasCursor: boolean + hasCursorAppearedRef: React.RefObject + setActiveTab: React.Dispatch> +} -export type { TabsContext }; +export type { TabsContext } diff --git a/src/components/tabs/types/tabs-cursor.ts b/src/components/tabs/types/tabs-cursor.ts index 5e7840b..c78f405 100644 --- a/src/components/tabs/types/tabs-cursor.ts +++ b/src/components/tabs/types/tabs-cursor.ts @@ -1,8 +1,8 @@ -import { m } from "framer-motion"; -import React from "react"; +import { m } from 'framer-motion' +import React from 'react' -type TabsCursorPrimitive = typeof m.span; +type TabsCursorPrimitive = typeof m.span -type TabsCursorProps = React.ComponentPropsWithRef; +type TabsCursorProps = React.ComponentPropsWithRef -export type { TabsCursorProps }; +export type { TabsCursorProps } diff --git a/src/components/tabs/types/tabs-trigger-children-container.ts b/src/components/tabs/types/tabs-trigger-children-container.ts index 05071dc..165e36a 100644 --- a/src/components/tabs/types/tabs-trigger-children-container.ts +++ b/src/components/tabs/types/tabs-trigger-children-container.ts @@ -1,5 +1,5 @@ -import React from "react"; +import React from 'react' -type TabsTriggerChildrenContainerProps = React.ComponentPropsWithRef<"span">; +type TabsTriggerChildrenContainerProps = React.ComponentPropsWithRef<'span'> -export type { TabsTriggerChildrenContainerProps }; +export type { TabsTriggerChildrenContainerProps } diff --git a/src/components/tabs/types/tabs-trigger-list.ts b/src/components/tabs/types/tabs-trigger-list.ts index 73cf093..fe8c51e 100644 --- a/src/components/tabs/types/tabs-trigger-list.ts +++ b/src/components/tabs/types/tabs-trigger-list.ts @@ -1,11 +1,10 @@ -import { TabsList as TabsTriggerListPrimitive } from "@radix-ui/react-tabs"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { TabsList as TabsTriggerListPrimitive } from '@radix-ui/react-tabs' +import { Simplify } from '@/components/_shared/types/simplify' -type TabsTriggerListPrimitiveType = typeof TabsTriggerListPrimitive; +type TabsTriggerListPrimitiveType = typeof TabsTriggerListPrimitive -type TabsTriggerListPrimitiveProps = - React.ComponentProps; +type TabsTriggerListPrimitiveProps = React.ComponentProps -type TabsTriggerListProps = Simplify; +type TabsTriggerListProps = Simplify -export type { TabsTriggerListProps }; +export type { TabsTriggerListProps } diff --git a/src/components/tabs/types/tabs-trigger.ts b/src/components/tabs/types/tabs-trigger.ts index df28242..9877161 100644 --- a/src/components/tabs/types/tabs-trigger.ts +++ b/src/components/tabs/types/tabs-trigger.ts @@ -1,39 +1,37 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { ButtonProps } from "@/components/button"; -import { TabsCursor } from "@/components/tabs/components/tabs-cursor"; -import { TabsTriggerChildrenContainer } from "@/components/tabs/components/tabs-trigger-children-container"; +import { ButtonProps } from '@/components/button' +import { TabsCursor } from '@/components/tabs/components/tabs-cursor' +import { TabsTriggerChildrenContainer } from '@/components/tabs/components/tabs-trigger-children-container' -type TabsTriggerButtonProps = Omit; +type TabsTriggerButtonProps = Omit type TabsTriggerChildrenProps = { - isSelected: boolean; - Cursor: typeof TabsCursor; - ChildrenContainer: typeof TabsTriggerChildrenContainer; -}; + isSelected: boolean + Cursor: typeof TabsCursor + ChildrenContainer: typeof TabsTriggerChildrenContainer +} type TabsTriggerTriggerProps = { - value: string | number; - childrenContainerProps?: React.ComponentPropsWithRef<"span">; -}; + value: string | number + childrenContainerProps?: React.ComponentPropsWithRef<'span'> +} type TabsTriggerTriggerAsChildProps = { - asChild: true; - children?: (props: TabsTriggerChildrenProps) => React.ReactNode; -}; + asChild: true + children?: (props: TabsTriggerChildrenProps) => React.ReactNode +} type TabsTriggerTriggerNoAsChildProps = { - asChild?: false; - children?: - | ((props: TabsTriggerChildrenProps) => React.ReactNode) - | React.ReactNode; -}; + asChild?: false + children?: ((props: TabsTriggerChildrenProps) => React.ReactNode) | React.ReactNode +} type TabsTriggerProps = Simplify< - TabsTriggerButtonProps & - TabsTriggerTriggerProps & - (TabsTriggerTriggerAsChildProps | TabsTriggerTriggerNoAsChildProps) ->; + TabsTriggerButtonProps & + TabsTriggerTriggerProps & + (TabsTriggerTriggerAsChildProps | TabsTriggerTriggerNoAsChildProps) +> -export type { TabsTriggerProps }; +export type { TabsTriggerProps } diff --git a/src/components/tabs/types/tabs.ts b/src/components/tabs/types/tabs.ts index 1ac120e..096afcd 100644 --- a/src/components/tabs/types/tabs.ts +++ b/src/components/tabs/types/tabs.ts @@ -1,31 +1,29 @@ -import { Tabs as TabsPrimitive } from "@radix-ui/react-tabs"; -import { Simplify } from "@/components/_shared/types/simplify"; +import { Tabs as TabsPrimitive } from '@radix-ui/react-tabs' +import { Simplify } from '@/components/_shared/types/simplify' -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { ButtonProps } from "@/components/button/types/button"; -import { tabsCursorClasses } from "@/components/tabs/classes/tabs-cursor-classes"; +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { ButtonProps } from '@/components/button/types/button' +import { tabsCursorClasses } from '@/components/tabs/classes/tabs-cursor-classes' -type TabsPrimitiveType = typeof TabsPrimitive; +type TabsPrimitiveType = typeof TabsPrimitive type TabsPrimitiveProps = Omit< - React.ComponentProps, - "defaultValue" | "value" | "onValueChange" | "activationMode" ->; + React.ComponentProps, + 'defaultValue' | 'value' | 'onValueChange' | 'activationMode' +> type TabsCustomProps = { - type?: "focus" | "click"; - color?: ButtonProps["color"]; - defaultValue?: string | number; - value?: string | number; - animationDuration?: number; - hasCursor?: boolean; - onValueChange?: (value: any) => void; -}; + type?: 'focus' | 'click' + color?: ButtonProps['color'] + defaultValue?: string | number + value?: string | number + animationDuration?: number + hasCursor?: boolean + onValueChange?: (value: any) => void +} -type TabsVariantProps = NonNullableVariantProps; +type TabsVariantProps = NonNullableVariantProps -type TabsProps = Simplify< - TabsPrimitiveProps & TabsCustomProps & TabsVariantProps ->; +type TabsProps = Simplify -export type { TabsProps }; +export type { TabsProps } diff --git a/src/components/tabs/utils/get-handdle-trigger-press.ts b/src/components/tabs/utils/get-handdle-trigger-press.ts index c26dac9..e8ffdb1 100644 --- a/src/components/tabs/utils/get-handdle-trigger-press.ts +++ b/src/components/tabs/utils/get-handdle-trigger-press.ts @@ -1,15 +1,15 @@ import { TabsContext } from '@/components/tabs/types/tabs-context' function handleTriggerPress(value: string | number, setActiveTab: TabsContext['setActiveTab']) { - return () => setActiveTab(value) + return () => setActiveTab(value) } function getHandleTriggerPress( - type: TabsContext['type'], - value: string | number, - setActiveTab: TabsContext['setActiveTab'], + type: TabsContext['type'], + value: string | number, + setActiveTab: TabsContext['setActiveTab'], ) { - return type === 'focus' ? undefined : handleTriggerPress(value, setActiveTab) + return type === 'focus' ? undefined : handleTriggerPress(value, setActiveTab) } export { getHandleTriggerPress } diff --git a/src/components/tabs/utils/get-merged-cursor-transition.ts b/src/components/tabs/utils/get-merged-cursor-transition.ts index 7452b63..2a01baf 100644 --- a/src/components/tabs/utils/get-merged-cursor-transition.ts +++ b/src/components/tabs/utils/get-merged-cursor-transition.ts @@ -3,16 +3,16 @@ import { TabsCursorProps } from '@/components/tabs/types/tabs-cursor' import { TabsProps } from '@/components/tabs/types/tabs' function getMergedCursorTransition( - transition: TabsCursorProps['transition'], - animationDuration: TabsProps['animationDuration'], + transition: TabsCursorProps['transition'], + animationDuration: TabsProps['animationDuration'], ) { - return { - ...DEFAULT_TABS_CURSOR_TRANISTION, - ...(animationDuration - ? { duration: Number.parseFloat((animationDuration / 1000).toFixed(2)) } - : {}), - ...transition, - } + return { + ...DEFAULT_TABS_CURSOR_TRANISTION, + ...(animationDuration + ? { duration: Number.parseFloat((animationDuration / 1000).toFixed(2)) } + : {}), + ...transition, + } } export { getMergedCursorTransition } diff --git a/src/components/text-area/components/text-area.tsx b/src/components/text-area/components/text-area.tsx index bb824d3..982274e 100644 --- a/src/components/text-area/components/text-area.tsx +++ b/src/components/text-area/components/text-area.tsx @@ -1,114 +1,105 @@ -"use client"; +'use client' -import { - chain, - cn, - cx, - functionCallOrValue, - getOptionalObject, - polymorphic, -} from "@renderui/utils"; -import React from "react"; +import { chain, cn, cx, functionCallOrValue, getOptionalObject, polymorphic } from '@renderui/utils' +import React from 'react' -import { inputContainerClasses } from "@/components/_shared/classes/input-container-classes"; -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { Aria } from "@/components/aria"; +import { inputContainerClasses } from '@/components/_shared/classes/input-container-classes' +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { Aria } from '@/components/aria' import { - DEFAULT_TEXT_AREA_CLASSNAME, - DEFAULT_TEXT_AREA_CONTAINER_CLASSNAME, -} from "@/components/text-area/constants/constants"; -import { TextAreaProps } from "@/components/text-area/types/text-area"; + DEFAULT_TEXT_AREA_CLASSNAME, + DEFAULT_TEXT_AREA_CONTAINER_CLASSNAME, +} from '@/components/text-area/constants/constants' +import { TextAreaProps } from '@/components/text-area/types/text-area' const TextArea = (props: TextAreaProps) => { - const { - asChild, - value: valueProp, - children, - className, - style, - isDisabled, - isReadOnly, - isInvalid, - isRequired, - startContent, - endContent, - inputContainerProps, - onChange, - onValueChange, - variant = "solid", - defaultValue = "", - minHeight = 80, - maxHeight = 200, - ...restProps - } = props; + const { + asChild, + value: valueProp, + children, + className, + style, + isDisabled, + isReadOnly, + isInvalid, + isRequired, + startContent, + endContent, + inputContainerProps, + onChange, + onValueChange, + variant = 'solid', + defaultValue = '', + minHeight = 80, + maxHeight = 200, + ...restProps + } = props - const [value, setValue] = useControllableState({ - prop: valueProp as string, - defaultProp: defaultValue as string, - onChange: onValueChange, - }); + const [value, setValue] = useControllableState({ + prop: valueProp as string, + defaultProp: defaultValue as string, + onChange: onValueChange, + }) - const { - className: inputContainerClassName, - isTextInput = true, - isFocusWithin = true, - isUsingAriaPressProps = false, - ...restInputContainerProps - } = getOptionalObject(inputContainerProps); + const { + className: inputContainerClassName, + isTextInput = true, + isFocusWithin = true, + isUsingAriaPressProps = false, + ...restInputContainerProps + } = getOptionalObject(inputContainerProps) - const Component = polymorphic(asChild, "textarea"); + const Component = polymorphic(asChild, 'textarea') - return ( - - {functionCallOrValue(startContent, value)} - {functionCallOrValue(children, value)} - ) => - setValue(event.target.value) - )} - {...restProps} - /> - {functionCallOrValue(endContent, value)} - - ); -}; + return ( + + {functionCallOrValue(startContent, value)} + {functionCallOrValue(children, value)} + ) => + setValue(event.target.value), + )} + {...restProps} + /> + {functionCallOrValue(endContent, value)} + + ) +} -export { TextArea }; +export { TextArea } diff --git a/src/components/text-area/constants/constants.ts b/src/components/text-area/constants/constants.ts index 923fbce..bb6eea1 100644 --- a/src/components/text-area/constants/constants.ts +++ b/src/components/text-area/constants/constants.ts @@ -1,7 +1,7 @@ const DEFAULT_TEXT_AREA_CONTAINER_CLASSNAME = - 'render-ui-text-area-container min-h-[var(--min-height)] h-[auto] max-h-fit' + 'render-ui-text-area-container min-h-[var(--min-height)] h-[auto] max-h-fit' const DEFAULT_TEXT_AREA_CLASSNAME = - 'render-ui-text-area relative z-[1] max-h-[var(--max-height)] min-h-[inherit] m-0 p-0 w-full h-full block border-none appearance-none rounded bg-transparent p-3 text-sm text-mode-contrast outline-none data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' + 'render-ui-text-area relative z-[1] max-h-[var(--max-height)] min-h-[inherit] m-0 p-0 w-full h-full block border-none appearance-none rounded bg-transparent p-3 text-sm text-mode-contrast outline-none data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' export { DEFAULT_TEXT_AREA_CLASSNAME, DEFAULT_TEXT_AREA_CONTAINER_CLASSNAME } diff --git a/src/components/text-area/types/text-area.ts b/src/components/text-area/types/text-area.ts index a9eb2a4..59d42f2 100644 --- a/src/components/text-area/types/text-area.ts +++ b/src/components/text-area/types/text-area.ts @@ -1,34 +1,34 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { Aria } from "@/components/aria"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { Aria } from '@/components/aria' type TextAreaHTMLProps = Omit< - React.ComponentPropsWithRef<"textarea">, - "children" | "disabled" | "readonly" ->; + React.ComponentPropsWithRef<'textarea'>, + 'children' | 'disabled' | 'readonly' +> type TextAreaCustomProps = { - children?: React.ReactNode | ((value: string) => React.ReactNode); - startContent?: React.ReactNode | ((value: string) => React.ReactNode); - endContent?: React.ReactNode | ((value: string) => React.ReactNode); - isReadOnly?: boolean; - isInvalid?: boolean; - isDisabled?: boolean; - isRequired?: boolean; - inputContainerProps?: React.ComponentPropsWithRef; - minHeight?: number | `${number}`; - maxHeight?: number | `${number}`; - onValueChange?: (value: string) => void; -}; + children?: React.ReactNode | ((value: string) => React.ReactNode) + startContent?: React.ReactNode | ((value: string) => React.ReactNode) + endContent?: React.ReactNode | ((value: string) => React.ReactNode) + isReadOnly?: boolean + isInvalid?: boolean + isDisabled?: boolean + isRequired?: boolean + inputContainerProps?: React.ComponentPropsWithRef + minHeight?: number | `${number}` + maxHeight?: number | `${number}` + onValueChange?: (value: string) => void +} type TextVariantProps = { - variant?: "solid" | "outline"; -}; + variant?: 'solid' | 'outline' +} type TextAreaProps = Simplify< - TextAreaHTMLProps & TextAreaCustomProps & TextVariantProps & AsChildProp ->; + TextAreaHTMLProps & TextAreaCustomProps & TextVariantProps & AsChildProp +> -export type { TextAreaProps }; +export type { TextAreaProps } diff --git a/src/components/text-input/components/password-toggle.tsx b/src/components/text-input/components/password-toggle.tsx index 6dcfaf0..80275f7 100644 --- a/src/components/text-input/components/password-toggle.tsx +++ b/src/components/text-input/components/password-toggle.tsx @@ -5,41 +5,41 @@ import { EyeNoneIcon } from '@/components/_shared/components/icons/eye-none-icon import { EyeOpenIcon } from '@/components/_shared/components/icons/eye-open-icon' import { Button } from '@/components/button' import { - DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, - DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, + DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, + DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, } from '@/components/text-input/constants/constants' import { PasswordToggleProps } from '@/components/text-input/types/password-toggle' const PasswordToggle = (props: PasswordToggleProps) => { - const { className, type, variant = 'plain', passwordToggleIconProps, ...restProps } = props + const { className, type, variant = 'plain', passwordToggleIconProps, ...restProps } = props - const { className: passwordToggleIconClassName, ...restPasswordToggleIconProps } = - getOptionalObject(passwordToggleIconProps) + const { className: passwordToggleIconClassName, ...restPasswordToggleIconProps } = + getOptionalObject(passwordToggleIconProps) - return ( - - ) + return ( + + ) } export { PasswordToggle } diff --git a/src/components/text-input/components/text-input.tsx b/src/components/text-input/components/text-input.tsx index 29aa565..2a53d69 100644 --- a/src/components/text-input/components/text-input.tsx +++ b/src/components/text-input/components/text-input.tsx @@ -1,54 +1,46 @@ -"use client"; +'use client' -import { polymorphic } from "@renderui/utils"; -import React from "react"; +import { polymorphic } from '@renderui/utils' +import React from 'react' -import { CrossSmallIcon } from "@/components/_shared/components/icons/cross-small-icon"; -import { Aria } from "@/components/aria"; -import { Button } from "@/components/button"; -import { PasswordToggle } from "@/components/text-input/components/password-toggle"; -import { useTextInput } from "@/components/text-input/hooks/use-text-input"; -import { - TextInputProps, - TextInputRef, -} from "@/components/text-input/types/text-input"; +import { CrossSmallIcon } from '@/components/_shared/components/icons/cross-small-icon' +import { Aria } from '@/components/aria' +import { Button } from '@/components/button' +import { PasswordToggle } from '@/components/text-input/components/password-toggle' +import { useTextInput } from '@/components/text-input/hooks/use-text-input' +import { TextInputProps, TextInputRef } from '@/components/text-input/types/text-input' const TextInput = (props: TextInputProps) => { - const { - inputContainerProps, - inputProps, - clearButtonProps, - clearButtonIconProps, - passwordToggleProps, - utilityProps, - } = useTextInput(props); - - const { - children, - startContent, - endContent, - shouldRenderClearButton, - hasPasswordToggle, - } = utilityProps; - - const { asChild, ...restInputProps } = inputProps; - - const InputComponent = polymorphic(asChild, "input"); - - return ( - - {startContent} - - {shouldRenderClearButton ? ( - - ) : null} - {hasPasswordToggle ? : null} - {children} - {endContent} - - ); -}; - -export { TextInput }; + const { + inputContainerProps, + inputProps, + clearButtonProps, + clearButtonIconProps, + passwordToggleProps, + utilityProps, + } = useTextInput(props) + + const { children, startContent, endContent, shouldRenderClearButton, hasPasswordToggle } = + utilityProps + + const { asChild, ...restInputProps } = inputProps + + const InputComponent = polymorphic(asChild, 'input') + + return ( + + {startContent} + + {shouldRenderClearButton ? ( + + ) : null} + {hasPasswordToggle ? : null} + {children} + {endContent} + + ) +} + +export { TextInput } diff --git a/src/components/text-input/constants/constants.ts b/src/components/text-input/constants/constants.ts index aadcf39..8a43bc6 100644 --- a/src/components/text-input/constants/constants.ts +++ b/src/components/text-input/constants/constants.ts @@ -6,28 +6,28 @@ const TEXT_INPUT_CONTAINER_BASE_PADDING = 'pr-3' const TEXT_INPUT_CONTAINER_ACTIONS_PADDING = 'pr-1.5' const DEFAULT_TEXT_INPUT_CLASSNAME = - 'render-ui-text_input relative z-[1] text-elipsis h-full w-full min-w-[0px] pl-3 overflow-hidden bg-transparent text-sm text-mode-contrast outline-none data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' + 'render-ui-text_input relative z-[1] text-elipsis h-full w-full min-w-[0px] pl-3 overflow-hidden bg-transparent text-sm text-mode-contrast outline-none data-[disabled=true]:cursor-[inherit] data-[disabled=true]:pointer-events-none placeholder:text-mode-foreground/50' const DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME = - 'render-ui-text_input-password-toggle relative z-[10] flex h-6 w-6 mr-2 shrink-0 items-center justify-center rounded-full ring-offset-mode-accent p-0 [&]:data-[focus-visible=true]:ring-[2px]' + 'render-ui-text_input-password-toggle relative z-[10] flex h-6 w-6 mr-2 shrink-0 items-center justify-center rounded-full ring-offset-mode-accent p-0 [&]:data-[focus-visible=true]:ring-[2px]' const DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME = - 'render-ui-text_input-password-toggle-icon pointer-events-none absolute inset-0 left-1/2 top-1/2 z-[1] -translate-x-1/2 -translate-y-1/2 text-mode-contrast-accent/90 transition-[opacit,color] duration-fast' + 'render-ui-text_input-password-toggle-icon pointer-events-none absolute inset-0 left-1/2 top-1/2 z-[1] -translate-x-1/2 -translate-y-1/2 text-mode-contrast-accent/90 transition-[opacit,color] duration-fast' const DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME = - 'render-ui-text_input-clear-button h-6 w-6 shrink-0 rounded-full bg-mode-accent/50 p-0 [&]:data-[focus-visible=true]:ring-[2px]' + 'render-ui-text_input-clear-button h-6 w-6 shrink-0 rounded-full bg-mode-accent/50 p-0 [&]:data-[focus-visible=true]:ring-[2px]' const DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME = - 'render-ui-text_input-clear-button-icon text-mode-contrast-accent/90 transition-[color] duration-fast' + 'render-ui-text_input-clear-button-icon text-mode-contrast-accent/90 transition-[color] duration-fast' export { - CLEAR_TOGGLE_TIMEOUT, - DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, - DEFAULT_TEXT_INPUT_CLASSNAME, - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, - DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, - DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, - TEXT_INPUT_CONTAINER_ACTIONS_PADDING, - TEXT_INPUT_CONTAINER_BASE_PADDING, + CLEAR_TOGGLE_TIMEOUT, + DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, + DEFAULT_TEXT_INPUT_CLASSNAME, + DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, + DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, + DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, + DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, + TEXT_INPUT_CONTAINER_ACTIONS_PADDING, + TEXT_INPUT_CONTAINER_BASE_PADDING, } diff --git a/src/components/text-input/hooks/use-input-actions.ts b/src/components/text-input/hooks/use-input-actions.ts index dc9a1ce..5500d9d 100644 --- a/src/components/text-input/hooks/use-input-actions.ts +++ b/src/components/text-input/hooks/use-input-actions.ts @@ -5,69 +5,69 @@ import { CLEAR_TOGGLE_TIMEOUT } from '@/components/text-input/constants/constant import { TextInputProps, TextInputRef } from '@/components/text-input/types/text-input' type UseInputActionsArgs = { - type: TextInputProps['type'] - onClear: TextInputProps['onClear'] - setValue: React.Dispatch> + type: TextInputProps['type'] + onClear: TextInputProps['onClear'] + setValue: React.Dispatch> } const useInputActions = (args: UseInputActionsArgs, inputRef: React.RefObject) => { - const { type, onClear, setValue } = args + const { type, onClear, setValue } = args - const originalNonPasswordType = React.useRef(!type || type === 'password' ? 'text' : type) + const originalNonPasswordType = React.useRef(!type || type === 'password' ? 'text' : type) - const [inputType, setInputType] = React.useState(type ?? 'text') + const [inputType, setInputType] = React.useState(type ?? 'text') - const clickTimeout = React.useRef(null) + const clickTimeout = React.useRef(null) - const focusInputOnClickTimeout = () => { - if (clickTimeout.current) { - clearTimeout(clickTimeout.current) - clickTimeout.current = null - } + const focusInputOnClickTimeout = () => { + if (clickTimeout.current) { + clearTimeout(clickTimeout.current) + clickTimeout.current = null + } - clickTimeout.current = setTimeout(() => { - if (inputRef.current) focusInput(inputRef) - }, CLEAR_TOGGLE_TIMEOUT) - } + clickTimeout.current = setTimeout(() => { + if (inputRef.current) focusInput(inputRef) + }, CLEAR_TOGGLE_TIMEOUT) + } - const handleInputFocusOnContainerClick = () => { - if (inputRef.current) focusInput(inputRef) - } + const handleInputFocusOnContainerClick = () => { + if (inputRef.current) focusInput(inputRef) + } - const handleClear = () => { - setValue('') + const handleClear = () => { + setValue('') - if (inputRef.current) focusInputOnClickTimeout() + if (inputRef.current) focusInputOnClickTimeout() - if (onClear) onClear() - } + if (onClear) onClear() + } - const handlePasswordToggle = () => { - setInputType((previousType) => { - if (previousType === 'password') { - return originalNonPasswordType.current - } + const handlePasswordToggle = () => { + setInputType((previousType) => { + if (previousType === 'password') { + return originalNonPasswordType.current + } - return 'password' - }) + return 'password' + }) - if (inputRef.current) focusInputOnClickTimeout() - } + if (inputRef.current) focusInputOnClickTimeout() + } - const clearTimeouts = () => { - if (clickTimeout.current) { - clearTimeout(clickTimeout.current) - clickTimeout.current = null - } - } + const clearTimeouts = () => { + if (clickTimeout.current) { + clearTimeout(clickTimeout.current) + clickTimeout.current = null + } + } - return { - inputType, - handleClear, - clearTimeouts, - handleInputFocusOnContainerClick, - handlePasswordToggle, - } + return { + inputType, + handleClear, + clearTimeouts, + handleInputFocusOnContainerClick, + handlePasswordToggle, + } } export { useInputActions } diff --git a/src/components/text-input/hooks/use-text-input.ts b/src/components/text-input/hooks/use-text-input.ts index 57d14f6..2cab9b1 100644 --- a/src/components/text-input/hooks/use-text-input.ts +++ b/src/components/text-input/hooks/use-text-input.ts @@ -1,242 +1,217 @@ +import { cn, cx, functionCallOrValue, getOptionalObject } from '@renderui/utils' +import React from 'react' +import { chain } from 'react-aria' + +import { inputContainerClasses } from '@/components/_shared/classes/input-container-classes' +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { useMergedRef } from '@/components/_shared/hooks/use-merged-ref' +import { useOnClickOutside } from '@/components/_shared/hooks/use-on-click-outside' import { - cn, - cx, - functionCallOrValue, - getOptionalObject, -} from "@renderui/utils"; -import React from "react"; -import { chain } from "react-aria"; - -import { inputContainerClasses } from "@/components/_shared/classes/input-container-classes"; -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { useMergedRef } from "@/components/_shared/hooks/use-merged-ref"; -import { useOnClickOutside } from "@/components/_shared/hooks/use-on-click-outside"; -import { - DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, - DEFAULT_TEXT_INPUT_CLASSNAME, - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, - DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, - DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, - TEXT_INPUT_CONTAINER_ACTIONS_PADDING, - TEXT_INPUT_CONTAINER_BASE_PADDING, -} from "@/components/text-input/constants/constants"; -import { useInputActions } from "@/components/text-input/hooks/use-input-actions"; -import { TextInputProps } from "@/components/text-input/types/text-input"; + DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, + DEFAULT_TEXT_INPUT_CLASSNAME, + DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, + DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, + DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, + DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, + TEXT_INPUT_CONTAINER_ACTIONS_PADDING, + TEXT_INPUT_CONTAINER_BASE_PADDING, +} from '@/components/text-input/constants/constants' +import { useInputActions } from '@/components/text-input/hooks/use-input-actions' +import { TextInputProps } from '@/components/text-input/types/text-input' function useTextInput(props: TextInputProps) { - const { - ref, - defaultValue, - value: valueProp, - isDisabled, - isReadOnly, - isInvalid, - isRequired, - className, - children, - startContent, - endContent, - hasClearButton, - hasClearButtonAlways, - hasPasswordToggle, - inputContainerProps, - clearButtonProps, - clearButtonIconProps, - passwordToggleProps, - passwordToggleIconProps, - onClear, - onClick, - onPointerDown, - onValueChange, - onChange: nativeOnChange, - variant = "solid", - size = "md", - type = "text", - ...restProps - } = props; - - const [value, setValue] = useControllableState({ - prop: valueProp as string, - defaultProp: defaultValue as string, - onChange: onValueChange, - }); - - const internalInputRef = React.useRef(null); - const mergedRefCallback = useMergedRef([ - internalInputRef, - ref, - ]); - - const { - inputType, - clearTimeouts, - handleClear, - handleInputFocusOnContainerClick, - handlePasswordToggle, - } = useInputActions( - { - type, - setValue, - onClear, - }, - internalInputRef - ); - - useOnClickOutside({ - event: "pointerdown", - element: internalInputRef.current, - handler: clearTimeouts, - }); - - const shouldRenderClearButton = - hasClearButtonAlways || - (hasClearButton && typeof value === "string" && value.length > 0); - - const { - className: inputContainerClassName, - onClick: inputContainerOnClick, - onPointerDown: inputContainerOnPointerDown, - isTextInput = true, - isFocusWithin = true, - isUsingAriaPressProps = false, - ...restInputContainerClassName - } = getOptionalObject(inputContainerProps); - - const { - onPress: clearButtonOnPress, - className: clearButtonClassName, - variant: clearButtonVariant = "plain", - ...restClearButtonProps - } = getOptionalObject(clearButtonProps); - - const { className: clearButtonIconClassName, ...restClearButtonIconProps } = - getOptionalObject(clearButtonIconProps); - - const { - className: passwordToggleClassName, - onPress: passwordToggleOnPress, - ...restPasswordToggleProps - } = getOptionalObject(passwordToggleProps); - - const { - className: passwordToggleIconClassName, - ...restPasswordToggleIconProps - } = getOptionalObject(passwordToggleIconProps); - - const chainedOnChange = (event: React.ChangeEvent) => { - if (nativeOnChange) nativeOnChange(event); - - setValue(event.target.value); - }; - - const forcedVariant = variant === "outline" ? "outline" : "solid"; - - return { - inputContainerProps: { - isTextInput, - isFocusWithin, - isDisabled, - isUsingAriaPressProps, - "data-disabled": isDisabled, - "data-readonly": isReadOnly, - "data-invalid": isInvalid, - "data-required": isRequired, - "data-slot": "base", - className: cx( - DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, - inputContainerClasses({ size, variant: forcedVariant }), - inputContainerClassName - ), - onPointerDown: chain( - ( - event: - | React.PointerEvent - | React.PointerEvent - ) => event.preventDefault(), - inputContainerOnPointerDown - ), - onClick: chain(handleInputFocusOnContainerClick, inputContainerOnClick), - ...restInputContainerClassName, - }, - inputProps: { - ref: mergedRefCallback, - onChange: chainedOnChange, - value: value ?? "", - "aria-disabled": isDisabled, - "aria-readonly": isReadOnly, - "aria-invalid": isInvalid, - "aria-required": isRequired, - "data-disabled": isDisabled, - "data-readonly": isReadOnly, - "data-invalid": isInvalid, - "data-required": isRequired, - "data-slot": "input", - disabled: isDisabled, - readOnly: isReadOnly, - type: inputType, - className: cn( - DEFAULT_TEXT_INPUT_CLASSNAME, - hasClearButton || hasPasswordToggle - ? TEXT_INPUT_CONTAINER_ACTIONS_PADDING - : TEXT_INPUT_CONTAINER_BASE_PADDING, - className - ), - onPointerDown: chain( - (event: React.PointerEvent) => - event.stopPropagation(), - onPointerDown - ), - onClick: chain( - (event: React.MouseEvent) => - event.stopPropagation(), - onClick - ), - ...restProps, - }, - clearButtonProps: { - "data-slot": "clear-button", - variant: clearButtonVariant, - className: cn( - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, - clearButtonClassName - ), - onPress: chain(handleClear, clearButtonOnPress), - ...restClearButtonProps, - }, - clearButtonIconProps: { - "data-slot": "clear-button-icon", - className: cn( - DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, - clearButtonIconClassName - ), - ...restClearButtonIconProps, - }, - passwordToggleProps: { - type: inputType, - "data-slot": "password-toggle", - onPress: chain(handlePasswordToggle, passwordToggleOnPress), - className: cn( - DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, - passwordToggleClassName - ), - passwordToggleIconProps: { - className: cn( - DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, - passwordToggleIconClassName - ), - ...restPasswordToggleIconProps, - }, - ...restPasswordToggleProps, - }, - utilityProps: { - shouldRenderClearButton, - hasPasswordToggle, - startContent: functionCallOrValue(startContent, value), - children: functionCallOrValue(children, value), - endContent: functionCallOrValue(endContent, value), - }, - }; + const { + ref, + defaultValue, + value: valueProp, + isDisabled, + isReadOnly, + isInvalid, + isRequired, + className, + children, + startContent, + endContent, + hasClearButton, + hasClearButtonAlways, + hasPasswordToggle, + inputContainerProps, + clearButtonProps, + clearButtonIconProps, + passwordToggleProps, + passwordToggleIconProps, + onClear, + onClick, + onPointerDown, + onValueChange, + onChange: nativeOnChange, + variant = 'solid', + size = 'md', + type = 'text', + ...restProps + } = props + + const [value, setValue] = useControllableState({ + prop: valueProp as string, + defaultProp: defaultValue as string, + onChange: onValueChange, + }) + + const internalInputRef = React.useRef(null) + const mergedRefCallback = useMergedRef([internalInputRef, ref]) + + const { + inputType, + clearTimeouts, + handleClear, + handleInputFocusOnContainerClick, + handlePasswordToggle, + } = useInputActions( + { + type, + setValue, + onClear, + }, + internalInputRef, + ) + + useOnClickOutside({ + event: 'pointerdown', + element: internalInputRef.current, + handler: clearTimeouts, + }) + + const shouldRenderClearButton = + hasClearButtonAlways || (hasClearButton && typeof value === 'string' && value.length > 0) + + const { + className: inputContainerClassName, + onClick: inputContainerOnClick, + onPointerDown: inputContainerOnPointerDown, + isTextInput = true, + isFocusWithin = true, + isUsingAriaPressProps = false, + ...restInputContainerClassName + } = getOptionalObject(inputContainerProps) + + const { + onPress: clearButtonOnPress, + className: clearButtonClassName, + variant: clearButtonVariant = 'plain', + ...restClearButtonProps + } = getOptionalObject(clearButtonProps) + + const { className: clearButtonIconClassName, ...restClearButtonIconProps } = + getOptionalObject(clearButtonIconProps) + + const { + className: passwordToggleClassName, + onPress: passwordToggleOnPress, + ...restPasswordToggleProps + } = getOptionalObject(passwordToggleProps) + + const { className: passwordToggleIconClassName, ...restPasswordToggleIconProps } = + getOptionalObject(passwordToggleIconProps) + + const chainedOnChange = (event: React.ChangeEvent) => { + if (nativeOnChange) nativeOnChange(event) + + setValue(event.target.value) + } + + const forcedVariant = variant === 'outline' ? 'outline' : 'solid' + + return { + inputContainerProps: { + isTextInput, + isFocusWithin, + isDisabled, + isUsingAriaPressProps, + 'data-disabled': isDisabled, + 'data-readonly': isReadOnly, + 'data-invalid': isInvalid, + 'data-required': isRequired, + 'data-slot': 'base', + className: cx( + DEFAULT_TEXT_INPUT_CONTAINER_CLASSNAME, + inputContainerClasses({ size, variant: forcedVariant }), + inputContainerClassName, + ), + onPointerDown: chain( + (event: React.PointerEvent | React.PointerEvent) => + event.preventDefault(), + inputContainerOnPointerDown, + ), + onClick: chain(handleInputFocusOnContainerClick, inputContainerOnClick), + ...restInputContainerClassName, + }, + inputProps: { + ref: mergedRefCallback, + onChange: chainedOnChange, + value: value ?? '', + 'aria-disabled': isDisabled, + 'aria-readonly': isReadOnly, + 'aria-invalid': isInvalid, + 'aria-required': isRequired, + 'data-disabled': isDisabled, + 'data-readonly': isReadOnly, + 'data-invalid': isInvalid, + 'data-required': isRequired, + 'data-slot': 'input', + disabled: isDisabled, + readOnly: isReadOnly, + type: inputType, + className: cn( + DEFAULT_TEXT_INPUT_CLASSNAME, + hasClearButton || hasPasswordToggle + ? TEXT_INPUT_CONTAINER_ACTIONS_PADDING + : TEXT_INPUT_CONTAINER_BASE_PADDING, + className, + ), + onPointerDown: chain( + (event: React.PointerEvent) => event.stopPropagation(), + onPointerDown, + ), + onClick: chain( + (event: React.MouseEvent) => event.stopPropagation(), + onClick, + ), + ...restProps, + }, + clearButtonProps: { + 'data-slot': 'clear-button', + variant: clearButtonVariant, + className: cn(DEFAULT_TEXT_INPUT_CLEAR_BUTTON_CLASSNAME, clearButtonClassName), + onPress: chain(handleClear, clearButtonOnPress), + ...restClearButtonProps, + }, + clearButtonIconProps: { + 'data-slot': 'clear-button-icon', + className: cn(DEFAULT_TEXT_INPUT_CLEAR_BUTTON_ICON_CLASSNAME, clearButtonIconClassName), + ...restClearButtonIconProps, + }, + passwordToggleProps: { + type: inputType, + 'data-slot': 'password-toggle', + onPress: chain(handlePasswordToggle, passwordToggleOnPress), + className: cn(DEFAULT_TEXT_INPUT_PASSWORD_TOGGLE_CLASSNAME, passwordToggleClassName), + passwordToggleIconProps: { + className: cn( + DEFAULT_TEXT_INPUT_BASE_PASSWORD_TOGGLE_ICON_CLASSNAME, + passwordToggleIconClassName, + ), + ...restPasswordToggleIconProps, + }, + ...restPasswordToggleProps, + }, + utilityProps: { + shouldRenderClearButton, + hasPasswordToggle, + startContent: functionCallOrValue(startContent, value), + children: functionCallOrValue(children, value), + endContent: functionCallOrValue(endContent, value), + }, + } } -export { useTextInput }; +export { useTextInput } diff --git a/src/components/text-input/types/password-toggle.ts b/src/components/text-input/types/password-toggle.ts index 389f6b7..d3bb55b 100644 --- a/src/components/text-input/types/password-toggle.ts +++ b/src/components/text-input/types/password-toggle.ts @@ -1,15 +1,13 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { EyeOpenIcon } from "@/components/_shared/components/icons/eye-open-icon"; -import { ButtonProps } from "@/components/button"; +import { EyeOpenIcon } from '@/components/_shared/components/icons/eye-open-icon' +import { ButtonProps } from '@/components/button' type PasswordToggleCustomProps = { - type: React.ComponentPropsWithRef<"input">["type"]; - passwordToggleIconProps?: React.ComponentPropsWithRef; -}; + type: React.ComponentPropsWithRef<'input'>['type'] + passwordToggleIconProps?: React.ComponentPropsWithRef +} -type PasswordToggleProps = Simplify< - Omit & PasswordToggleCustomProps ->; +type PasswordToggleProps = Simplify & PasswordToggleCustomProps> -export type { PasswordToggleProps }; +export type { PasswordToggleProps } diff --git a/src/components/text-input/types/text-input.ts b/src/components/text-input/types/text-input.ts index cfd11f5..e28a59b 100644 --- a/src/components/text-input/types/text-input.ts +++ b/src/components/text-input/types/text-input.ts @@ -1,56 +1,45 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { inputContainerClasses } from "@/components/_shared/classes/input-container-classes"; -import { CrossSmallIcon } from "@/components/_shared/components/icons/cross-small-icon"; -import { EyeOpenIcon } from "@/components/_shared/components/icons/eye-open-icon"; -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { Aria } from "@/components/aria"; -import { ButtonProps } from "@/components/button"; +import { inputContainerClasses } from '@/components/_shared/classes/input-container-classes' +import { CrossSmallIcon } from '@/components/_shared/components/icons/cross-small-icon' +import { EyeOpenIcon } from '@/components/_shared/components/icons/eye-open-icon' +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { Aria } from '@/components/aria' +import { ButtonProps } from '@/components/button' -type TextInputRef = HTMLInputElement; +type TextInputRef = HTMLInputElement type TextInputHTMLProps = Omit< - React.ComponentPropsWithRef<"input">, - | "type" - | "children" - | "startContent" - | "endContent" - | "disabled" - | "readonly" - | "required" ->; + React.ComponentPropsWithRef<'input'>, + 'type' | 'children' | 'startContent' | 'endContent' | 'disabled' | 'readonly' | 'required' +> type TextInputCustomProps = { - type?: "text" | "password" | "email" | "search" | "tel" | "url"; - children?: React.ReactNode | ((value: string) => React.ReactNode); - startContent?: React.ReactNode | ((value: string) => React.ReactNode); - endContent?: React.ReactNode | ((value: string) => React.ReactNode); - hasPasswordToggle?: boolean; - hasClearButton?: boolean; - hasClearButtonAlways?: boolean; - inputContainerProps?: React.ComponentPropsWithRef; - clearButtonProps?: ButtonProps; - clearButtonIconProps?: React.ComponentPropsWithRef; - isDisabled?: boolean; - isReadOnly?: boolean; - isInvalid?: boolean; - isRequired?: boolean; - passwordToggleProps?: ButtonProps; - passwordToggleIconProps?: React.ComponentPropsWithRef; - onClear?: () => void; - onValueChange?: (value: string) => void; -}; + type?: 'text' | 'password' | 'email' | 'search' | 'tel' | 'url' + children?: React.ReactNode | ((value: string) => React.ReactNode) + startContent?: React.ReactNode | ((value: string) => React.ReactNode) + endContent?: React.ReactNode | ((value: string) => React.ReactNode) + hasPasswordToggle?: boolean + hasClearButton?: boolean + hasClearButtonAlways?: boolean + inputContainerProps?: React.ComponentPropsWithRef + clearButtonProps?: ButtonProps + clearButtonIconProps?: React.ComponentPropsWithRef + isDisabled?: boolean + isReadOnly?: boolean + isInvalid?: boolean + isRequired?: boolean + passwordToggleProps?: ButtonProps + passwordToggleIconProps?: React.ComponentPropsWithRef + onClear?: () => void + onValueChange?: (value: string) => void +} -type TextInputVariantProps = NonNullableVariantProps< - typeof inputContainerClasses ->; +type TextInputVariantProps = NonNullableVariantProps type TextInputProps = Simplify< - TextInputHTMLProps & - TextInputCustomProps & - TextInputVariantProps & - AsChildProp ->; + TextInputHTMLProps & TextInputCustomProps & TextInputVariantProps & AsChildProp +> -export type { TextInputProps, TextInputRef }; +export type { TextInputProps, TextInputRef } diff --git a/src/components/text/classes/text-classes.ts b/src/components/text/classes/text-classes.ts index fae304e..8cc7d50 100644 --- a/src/components/text/classes/text-classes.ts +++ b/src/components/text/classes/text-classes.ts @@ -7,28 +7,28 @@ import { textShadowVariants } from '@/components/_shared/variants/text-shadow' import { textSizeVariants } from '@/components/_shared/variants/text-size' const textClasses = cva('render-ui-text box-border whitespace-normal text-mode-contrast', { - variants: { - as: { - span: '', - div: '', - p: '', - }, - size: textSizeVariants, - textBreak: textBreakVariants, - shadow: textShadowVariants, - overflow: textOverflowVariants, - letterSpacing: letterSpacingVariants, - }, - compoundVariants: [ - { - overflow: ['elipsis', 'clip'], - as: 'span', - className: 'block', - }, - ], - defaultVariants: { - size: 'base', - }, + variants: { + as: { + span: '', + div: '', + p: '', + }, + size: textSizeVariants, + textBreak: textBreakVariants, + shadow: textShadowVariants, + overflow: textOverflowVariants, + letterSpacing: letterSpacingVariants, + }, + compoundVariants: [ + { + overflow: ['elipsis', 'clip'], + as: 'span', + className: 'block', + }, + ], + defaultVariants: { + size: 'base', + }, }) export { textClasses } diff --git a/src/components/text/components/text.tsx b/src/components/text/components/text.tsx index 8fae708..b201435 100644 --- a/src/components/text/components/text.tsx +++ b/src/components/text/components/text.tsx @@ -1,47 +1,47 @@ -import { cn, polymorphic } from "@renderui/utils"; -import React from "react"; +import { cn, polymorphic } from '@renderui/utils' +import React from 'react' -import { textClasses } from "@/components/text/classes/text-classes"; -import { TextProps } from "@/components/text/types/text"; +import { textClasses } from '@/components/text/classes/text-classes' +import { TextProps } from '@/components/text/types/text' const Text = (props: TextProps) => { - const { - asChild, - children, - className, - hasStartSpace, - hasEndSpace, - size, - overflow, - shadow, - letterSpacing, - textBreak, - as = "span", - ...restProps - } = props; + const { + asChild, + children, + className, + hasStartSpace, + hasEndSpace, + size, + overflow, + shadow, + letterSpacing, + textBreak, + as = 'span', + ...restProps + } = props - const Component = polymorphic(asChild, as); + const Component = polymorphic(asChild, as) - return ( - - {hasStartSpace ? <>  : null} - {children} - {hasEndSpace ? <>  : null} - - ); -}; + return ( + + {hasStartSpace ? <>  : null} + {children} + {hasEndSpace ? <>  : null} + + ) +} -export { Text }; +export { Text } diff --git a/src/components/text/types/text.ts b/src/components/text/types/text.ts index 435c70b..15e89f2 100644 --- a/src/components/text/types/text.ts +++ b/src/components/text/types/text.ts @@ -1,22 +1,19 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -import { AsChildProp } from "@/components/_shared/types/as-child"; -import { NonNullableVariantProps } from "@/components/_shared/types/variants"; -import { textClasses } from "@/components/text/classes/text-classes"; +import { AsChildProp } from '@/components/_shared/types/as-child' +import { NonNullableVariantProps } from '@/components/_shared/types/variants' +import { textClasses } from '@/components/text/classes/text-classes' -type TextPrimitiveProps = React.ComponentPropsWithRef<"span">; +type TextPrimitiveProps = React.ComponentPropsWithRef<'span'> type TextRenderUIProps = { - hasStartSpace?: boolean; - hasEndSpace?: boolean; -}; + hasStartSpace?: boolean + hasEndSpace?: boolean +} type TextProps = Simplify< - TextPrimitiveProps & - TextRenderUIProps & - NonNullableVariantProps & - AsChildProp ->; + TextPrimitiveProps & TextRenderUIProps & NonNullableVariantProps & AsChildProp +> -export type { TextProps }; +export type { TextProps } diff --git a/src/components/toast/components/toast.tsx b/src/components/toast/components/toast.tsx index f06a307..9c5d312 100644 --- a/src/components/toast/components/toast.tsx +++ b/src/components/toast/components/toast.tsx @@ -1,168 +1,142 @@ -"use client"; +'use client' -import { CrossSmallIcon } from "@/components/_shared/components/icons/cross-small-icon"; -import { DEFAULT_TOAST_PROPS } from "@/components/toast/constants/constants"; -import { - ToastClasses, - ToastContentProps, - ToastProps, -} from "@/components/toast/types/toast"; -import { chain, cn, getOptionalObject } from "@renderui/utils"; -import React from "react"; -import { toast } from "sonner"; +import { CrossSmallIcon } from '@/components/_shared/components/icons/cross-small-icon' +import { DEFAULT_TOAST_PROPS } from '@/components/toast/constants/constants' +import { ToastClasses, ToastContentProps, ToastProps } from '@/components/toast/types/toast' +import { chain, cn, getOptionalObject } from '@renderui/utils' +import React from 'react' +import { toast } from 'sonner' const ToastContent = (props: ToastContentProps) => { - const { - t, - title, - description, - styles, - closeButtonProps, - actionButtonProps, - children, - } = props; + const { t, title, description, styles, closeButtonProps, actionButtonProps, children } = props - const { - className: closeButtonClassName, - children: closeButtonChildren, - onClick: onCloseButtonClick, - ...restCloseButtonProps - } = getOptionalObject(closeButtonProps); + const { + className: closeButtonClassName, + children: closeButtonChildren, + onClick: onCloseButtonClick, + ...restCloseButtonProps + } = getOptionalObject(closeButtonProps) - const { - className: actionButtonClassName, - children: actionButtonChildren, - onClick: onActionButtonClick, - ...restActionButtonProps - } = getOptionalObject(actionButtonProps); + const { + className: actionButtonClassName, + children: actionButtonChildren, + onClick: onActionButtonClick, + ...restActionButtonProps + } = getOptionalObject(actionButtonProps) - const { - title: titleClassName, - container: containerClassName, - button: buttonClassName, - description: descriptionClassname, - } = styles; + const { + title: titleClassName, + container: containerClassName, + button: buttonClassName, + description: descriptionClassname, + } = styles - return ( -
-
- {title ? ( -

- {title} -

- ) : null} - {description ? ( -

- {description} -

- ) : null} -
- {actionButtonProps ? ( - - ) : null} - {typeof children === "function" ? children(t) : children} - -
- ); -}; + return ( +
+
+ {title ? ( +

{title}

+ ) : null} + {description ? ( +

+ {description} +

+ ) : null} +
+ {actionButtonProps ? ( + + ) : null} + {typeof children === 'function' ? children(t) : children} + +
+ ) +} const toastFactory = (styles: ToastClasses) => { - return (props: ToastProps = {}) => { - const { - title, - description, - children, - closeButtonProps, - actionButtonProps, - ...restProps - } = props; + return (props: ToastProps = {}) => { + const { title, description, children, closeButtonProps, actionButtonProps, ...restProps } = + props - toast.custom( - (t) => ( - - ), - { ...DEFAULT_TOAST_PROPS, ...restProps } - ); - }; -}; + toast.custom( + (t) => ( + + ), + { ...DEFAULT_TOAST_PROPS, ...restProps }, + ) + } +} const toastDefault = toastFactory({ - container: "bg-mode border-neutral", - title: "text-mode-contrast", - description: "text-mode-contrast-accent", - button: "text-mode-contrast", -}); + container: 'bg-mode border-neutral', + title: 'text-mode-contrast', + description: 'text-mode-contrast-accent', + button: 'text-mode-contrast', +}) const toastSuccess = toastFactory({ - container: "bg-green-200 border-green-500/80", - title: "text-green-800", - description: "text-green-900", - button: "text-green-900 hover:bg-green-400/70", -}); + container: 'bg-green-200 border-green-500/80', + title: 'text-green-800', + description: 'text-green-900', + button: 'text-green-900 hover:bg-green-400/70', +}) const toastError = toastFactory({ - container: "bg-red-200 border-red-500/80", - title: "text-red-800", - description: "text-red-900", - button: "text-red-900 hover:bg-red-400/70", -}); + container: 'bg-red-200 border-red-500/80', + title: 'text-red-800', + description: 'text-red-900', + button: 'text-red-900 hover:bg-red-400/70', +}) const toastInfo = toastFactory({ - container: "bg-sky-200 border-sky-500/80", - title: "text-sky-800", - description: "text-sky-900", - button: "text-sky-900 hover:bg-sky-400/70", -}); + container: 'bg-sky-200 border-sky-500/80', + title: 'text-sky-800', + description: 'text-sky-900', + button: 'text-sky-900 hover:bg-sky-400/70', +}) const toastWarning = toastFactory({ - container: "bg-amber-200 border-amber-500/80", - title: "text-amber-800", - description: "text-amber-900", - button: "text-amber-900 hover:bg-amber-400/70", -}); + container: 'bg-amber-200 border-amber-500/80', + title: 'text-amber-800', + description: 'text-amber-900', + button: 'text-amber-900 hover:bg-amber-400/70', +}) -export { - toastDefault as toast, - toastError, - toastInfo, - toastSuccess, - toastWarning, -}; +export { toastDefault as toast, toastError, toastInfo, toastSuccess, toastWarning } -export type { ToastProps }; +export type { ToastProps } diff --git a/src/components/toast/constants/constants.ts b/src/components/toast/constants/constants.ts index 283be9f..8069df6 100644 --- a/src/components/toast/constants/constants.ts +++ b/src/components/toast/constants/constants.ts @@ -1,6 +1,6 @@ const DEFAULT_TOAST_PROPS = { - position: 'top-center', - duration: 3600, + position: 'top-center', + duration: 3600, } as const export { DEFAULT_TOAST_PROPS } diff --git a/src/components/toast/index.ts b/src/components/toast/index.ts index b744891..411743f 100644 --- a/src/components/toast/index.ts +++ b/src/components/toast/index.ts @@ -1,3 +1,3 @@ export * from '@/components/toast/components/toast' export * from '@/components/toast/components/toaster' -export * from '@/components/toast/types/toaster' \ No newline at end of file +export * from '@/components/toast/types/toaster' diff --git a/src/components/toast/types/toast.ts b/src/components/toast/types/toast.ts index df99a81..096fbce 100644 --- a/src/components/toast/types/toast.ts +++ b/src/components/toast/types/toast.ts @@ -1,39 +1,32 @@ -import { Simplify } from "@/components/_shared/types/simplify"; -import { toast } from "sonner"; +import { Simplify } from '@/components/_shared/types/simplify' +import { toast } from 'sonner' type ToastProps = Simplify< - Parameters<(typeof toast)["custom"]>[1] & { - title?: string; - description?: string; - children?: React.ReactNode | ((t: string | number) => React.ReactNode); - closeButtonProps?: React.ComponentPropsWithRef<"button">; - actionButtonProps?: Omit< - React.ComponentPropsWithRef<"button">, - "onClick" - > & { - onClick: (t: string | number) => void; - }; - } ->; + Parameters<(typeof toast)['custom']>[1] & { + title?: string + description?: string + children?: React.ReactNode | ((t: string | number) => React.ReactNode) + closeButtonProps?: React.ComponentPropsWithRef<'button'> + actionButtonProps?: Omit, 'onClick'> & { + onClick: (t: string | number) => void + } + } +> type ToastClasses = { - title: string; - description: string; - container: string; - button: string; -}; + title: string + description: string + container: string + button: string +} type ToastContentProps = { - t: string | number; + t: string | number } & Pick< - ToastProps, - | "title" - | "description" - | "children" - | "closeButtonProps" - | "actionButtonProps" + ToastProps, + 'title' | 'description' | 'children' | 'closeButtonProps' | 'actionButtonProps' > & { - styles: ToastClasses; - }; + styles: ToastClasses + } -export type { ToastProps, ToastClasses, ToastContentProps }; +export type { ToastProps, ToastClasses, ToastContentProps } diff --git a/src/components/toast/types/toaster.ts b/src/components/toast/types/toaster.ts index 836998b..8f9c936 100644 --- a/src/components/toast/types/toaster.ts +++ b/src/components/toast/types/toaster.ts @@ -1,5 +1,5 @@ -import { ExternalToast, Toaster, ToastT } from "sonner"; +import { ExternalToast, Toaster, ToastT } from 'sonner' -type ToasterProps = React.ComponentPropsWithRef; +type ToasterProps = React.ComponentPropsWithRef -export type { ExternalToast, ToasterProps, ToastT }; +export type { ExternalToast, ToasterProps, ToastT } diff --git a/src/components/toggle-group/components/toggle-group-item.tsx b/src/components/toggle-group/components/toggle-group-item.tsx index f3d3600..d1c872b 100644 --- a/src/components/toggle-group/components/toggle-group-item.tsx +++ b/src/components/toggle-group/components/toggle-group-item.tsx @@ -8,52 +8,52 @@ import React from 'react' import { Button } from '@/components/button' import { useToggleGroupContext } from '@/components/toggle-group/contexts/toggle-group-context' import { - ToggleGroupItemProps, - ToggleGroupItemRef, + ToggleGroupItemProps, + ToggleGroupItemRef, } from '@/components/toggle-group/types/toggle-group-item' import { - DEFAUL_TOGGLE_CLASSNAME, - TOGGLED_OFF_RING_CLASSNAME, + DEFAUL_TOGGLE_CLASSNAME, + TOGGLED_OFF_RING_CLASSNAME, } from '@/components/toggle/constants/constants' const ToggleGroupItem = React.forwardRef((props, ref) => { - const { - value, - className, - children, - variant, - hasRipple = false, - hasToggledOffRing = false, - color = 'primary', - ...restProps - } = props - - const { value: rootValue } = useToggleGroupContext() - - const isOn = Array.isArray(rootValue) - ? Boolean(rootValue.includes(value as never)) - : value.toString() === rootValue.toString() - - return ( - - - - ) + const { + value, + className, + children, + variant, + hasRipple = false, + hasToggledOffRing = false, + color = 'primary', + ...restProps + } = props + + const { value: rootValue } = useToggleGroupContext() + + const isOn = Array.isArray(rootValue) + ? Boolean(rootValue.includes(value as never)) + : value.toString() === rootValue.toString() + + return ( + + + + ) }) ToggleGroupItem.displayName = 'ToggleGroupItem' diff --git a/src/components/toggle-group/components/toggle-group.tsx b/src/components/toggle-group/components/toggle-group.tsx index e0fe8af..e6334cc 100644 --- a/src/components/toggle-group/components/toggle-group.tsx +++ b/src/components/toggle-group/components/toggle-group.tsx @@ -1,46 +1,46 @@ -"use client"; +'use client' -import { ToggleGroup as ToggleGroupPrimitive } from "@radix-ui/react-toggle-group"; -import { cn, functionCallOrValue } from "@renderui/utils"; -import React from "react"; +import { ToggleGroup as ToggleGroupPrimitive } from '@radix-ui/react-toggle-group' +import { cn, functionCallOrValue } from '@renderui/utils' +import React from 'react' -import { EMPTY_ARRAY } from "@/components/_shared/constants/constants"; -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { DEFAULT_TOGGLE_GROUP_CLASSNAME } from "@/components/toggle-group/constants/constants"; -import { ToggleGroupProvider } from "@/components/toggle-group/contexts/toggle-group-context"; -import { ToggleGroupProps } from "@/components/toggle-group/types/toggle-group"; +import { EMPTY_ARRAY } from '@/components/_shared/constants/constants' +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { DEFAULT_TOGGLE_GROUP_CLASSNAME } from '@/components/toggle-group/constants/constants' +import { ToggleGroupProvider } from '@/components/toggle-group/contexts/toggle-group-context' +import { ToggleGroupProps } from '@/components/toggle-group/types/toggle-group' const ToggleGroup = (props: ToggleGroupProps) => { - const { - onValueChange: onValueChangeProp, - value: valueProp, - className, - children, - type = "multiple", - defaultValue = type === "multiple" ? (EMPTY_ARRAY as string[]) : "", - ...restProps - } = props; + const { + onValueChange: onValueChangeProp, + value: valueProp, + className, + children, + type = 'multiple', + defaultValue = type === 'multiple' ? (EMPTY_ARRAY as string[]) : '', + ...restProps + } = props - const [value, onValueChange] = useControllableState({ - onChange: onValueChangeProp, - defaultProp: defaultValue, - prop: valueProp, - }); + const [value, onValueChange] = useControllableState({ + onChange: onValueChangeProp, + defaultProp: defaultValue, + prop: valueProp, + }) - return ( - - - {functionCallOrValue(children, { value, onValueChange })} - - - ); -}; + return ( + + + {functionCallOrValue(children, { value, onValueChange })} + + + ) +} -export { ToggleGroup }; +export { ToggleGroup } diff --git a/src/components/toggle-group/contexts/toggle-group-context.ts b/src/components/toggle-group/contexts/toggle-group-context.ts index b97262e..d2b97aa 100644 --- a/src/components/toggle-group/contexts/toggle-group-context.ts +++ b/src/components/toggle-group/contexts/toggle-group-context.ts @@ -3,12 +3,12 @@ import { initializeContext } from '@renderui/utils' import { ToggleGroupContext } from '@/components/toggle-group/types/toggle-group-context' const [ToggleGroupProvider, useToggleGroupContext] = initializeContext({ - errorMessage: - 'Components using useToggleGroupContext must be wrapped in a component.', - providerName: 'ToggleGroupProvider', - hookName: 'useToggleGroupContext', - name: 'ToggleGroupContext', - strict: true, + errorMessage: + 'Components using useToggleGroupContext must be wrapped in a component.', + providerName: 'ToggleGroupProvider', + hookName: 'useToggleGroupContext', + name: 'ToggleGroupContext', + strict: true, }) export { ToggleGroupProvider, useToggleGroupContext } diff --git a/src/components/toggle-group/index.ts b/src/components/toggle-group/index.ts index c0c4101..1c7ba72 100644 --- a/src/components/toggle-group/index.ts +++ b/src/components/toggle-group/index.ts @@ -1,4 +1,4 @@ export * from '@/components/toggle-group/components/toggle-group' export * from '@/components/toggle-group/components/toggle-group-item' export * from '@/components/toggle-group/types/toggle-group' -export * from '@/components/toggle-group/types/toggle-group-item' \ No newline at end of file +export * from '@/components/toggle-group/types/toggle-group-item' diff --git a/src/components/toggle-group/types/toggle-group-context.ts b/src/components/toggle-group/types/toggle-group-context.ts index 17b1538..b1b5d0d 100644 --- a/src/components/toggle-group/types/toggle-group-context.ts +++ b/src/components/toggle-group/types/toggle-group-context.ts @@ -1,5 +1,5 @@ type ToggleGroupContext = { - value: string[] | number[] | string | number + value: string[] | number[] | string | number } export type { ToggleGroupContext } diff --git a/src/components/toggle-group/types/toggle-group-item.ts b/src/components/toggle-group/types/toggle-group-item.ts index 500bcc8..2f9c5b7 100644 --- a/src/components/toggle-group/types/toggle-group-item.ts +++ b/src/components/toggle-group/types/toggle-group-item.ts @@ -1,18 +1,16 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { ButtonProps } from "@/components/button"; -import React from "react"; +import { ButtonProps } from '@/components/button' +import React from 'react' type ToggleGroupItemCustomProps = { - value: string | number; - hasToggledOffRing?: boolean; - children: - | (({ isOn }: { isOn: boolean }) => React.ReactNode) - | React.ReactNode; -}; + value: string | number + hasToggledOffRing?: boolean + children: (({ isOn }: { isOn: boolean }) => React.ReactNode) | React.ReactNode +} type ToggleGroupItemProps = Simplify< - Omit & ToggleGroupItemCustomProps ->; + Omit & ToggleGroupItemCustomProps +> -export type { ToggleGroupItemProps }; +export type { ToggleGroupItemProps } diff --git a/src/components/toggle-group/types/toggle-group.ts b/src/components/toggle-group/types/toggle-group.ts index f36889f..836e1ea 100644 --- a/src/components/toggle-group/types/toggle-group.ts +++ b/src/components/toggle-group/types/toggle-group.ts @@ -1,43 +1,43 @@ -import { ToggleGroup as ToggleGroupPrimitive } from "@radix-ui/react-toggle-group"; -import { Simplify } from "@/components/_shared/types/simplify"; -import React from "react"; +import { ToggleGroup as ToggleGroupPrimitive } from '@radix-ui/react-toggle-group' +import { Simplify } from '@/components/_shared/types/simplify' +import React from 'react' -type ToggleGroupPrimitiveType = typeof ToggleGroupPrimitive; +type ToggleGroupPrimitiveType = typeof ToggleGroupPrimitive type ToggleGroupPrimitiveProps = Omit< - React.ComponentPropsWithRef, - "value" | "defaultValue" | "onValueChange" | "type" ->; + React.ComponentPropsWithRef, + 'value' | 'defaultValue' | 'onValueChange' | 'type' +> type ToggleGroupCustomSingleProps = { - type: "single"; - value?: string | number; - defaultValue?: string | number; -}; + type: 'single' + value?: string | number + defaultValue?: string | number +} type ToggleGroupCustomMultipleProps = { - type: "multiple"; - value?: string[] | number[]; - defaultValue?: string[] | number[]; -}; + type: 'multiple' + value?: string[] | number[] + defaultValue?: string[] | number[] +} type ToggleGroupCustomBaseProps = { - onValueChange?: (value: any) => void; - children?: - | (({ - value, - onValueChange, - }: { - value: any; - onValueChange: React.Dispatch; - }) => React.ReactNode) - | React.ReactNode; -}; + onValueChange?: (value: any) => void + children?: + | (({ + value, + onValueChange, + }: { + value: any + onValueChange: React.Dispatch + }) => React.ReactNode) + | React.ReactNode +} type ToggleGroupProps = Simplify< - ToggleGroupPrimitiveProps & - (ToggleGroupCustomSingleProps | ToggleGroupCustomMultipleProps) & - ToggleGroupCustomBaseProps ->; + ToggleGroupPrimitiveProps & + (ToggleGroupCustomSingleProps | ToggleGroupCustomMultipleProps) & + ToggleGroupCustomBaseProps +> -export type { ToggleGroupProps }; +export type { ToggleGroupProps } diff --git a/src/components/toggle/components/toggle.tsx b/src/components/toggle/components/toggle.tsx index ab4c204..f73adca 100644 --- a/src/components/toggle/components/toggle.tsx +++ b/src/components/toggle/components/toggle.tsx @@ -1,46 +1,46 @@ -"use client"; +'use client' -import { Toggle as TogglePrimitive } from "@radix-ui/react-toggle"; -import { cn, functionCallOrValue } from "@renderui/utils"; -import React from "react"; +import { Toggle as TogglePrimitive } from '@radix-ui/react-toggle' +import { cn, functionCallOrValue } from '@renderui/utils' +import React from 'react' -import { useControllableState } from "@/components/_shared/hooks/use-controllable-state"; -import { Button } from "@/components/button"; -import { DEFAUL_TOGGLE_CLASSNAME } from "@/components/toggle/constants/constants"; -import { ToggleProps } from "@/components/toggle/types/toggle"; +import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' +import { Button } from '@/components/button' +import { DEFAUL_TOGGLE_CLASSNAME } from '@/components/toggle/constants/constants' +import { ToggleProps } from '@/components/toggle/types/toggle' const Toggle = (props: ToggleProps) => { - const { - onIsOnChange, - defaultIsOn, - isOn: isOnProp, - className, - children, - variant, - hasRipple = false, - color = "primary", - ...restProps - } = props; + const { + onIsOnChange, + defaultIsOn, + isOn: isOnProp, + className, + children, + variant, + hasRipple = false, + color = 'primary', + ...restProps + } = props - const [isOn, setIsOn] = useControllableState({ - onChange: onIsOnChange, - defaultProp: defaultIsOn, - prop: isOnProp, - }); + const [isOn, setIsOn] = useControllableState({ + onChange: onIsOnChange, + defaultProp: defaultIsOn, + prop: isOnProp, + }) - return ( - - - - ); -}; + return ( + + + + ) +} -export { Toggle }; +export { Toggle } diff --git a/src/components/toggle/constants/constants.ts b/src/components/toggle/constants/constants.ts index 5c1f364..6744c54 100644 --- a/src/components/toggle/constants/constants.ts +++ b/src/components/toggle/constants/constants.ts @@ -1,6 +1,6 @@ const DEFAUL_TOGGLE_CLASSNAME = 'render-ui-toggle min-w-fit' const TOGGLED_OFF_RING_CLASSNAME = - 'data-[state=off]:before:absolute data-[state=off]:before:left-0 data-[state=off]:before:top-0 data-[state=off]:before:size-full data-[state=off]:before:rounded-[inherit] data-[state=off]:before:ring data-[state=off]:before:ring-[2px] data-[state=off]:before:ring-inset data-[state=off]:before:ring-[rgba(var(--button-bg))]/60 data-[state=off]:before:ring-offset-[0px]' + 'data-[state=off]:before:absolute data-[state=off]:before:left-0 data-[state=off]:before:top-0 data-[state=off]:before:size-full data-[state=off]:before:rounded-[inherit] data-[state=off]:before:ring data-[state=off]:before:ring-[2px] data-[state=off]:before:ring-inset data-[state=off]:before:ring-[rgba(var(--button-bg))]/60 data-[state=off]:before:ring-offset-[0px]' export { DEFAUL_TOGGLE_CLASSNAME, TOGGLED_OFF_RING_CLASSNAME } diff --git a/src/components/toggle/types/toggle.ts b/src/components/toggle/types/toggle.ts index 1fb75be..1a1bfc6 100644 --- a/src/components/toggle/types/toggle.ts +++ b/src/components/toggle/types/toggle.ts @@ -1,18 +1,16 @@ -import { Simplify } from "@/components/_shared/types/simplify"; +import { Simplify } from '@/components/_shared/types/simplify' -import { ButtonProps } from "@/components/button"; +import { ButtonProps } from '@/components/button' -type TogglePrimitiveProps = Omit; +type TogglePrimitiveProps = Omit type ToggleCustomProps = { - isOn?: boolean; - defaultIsOn?: boolean; - onIsOnChange?: (isOn: boolean | undefined) => void; - children?: - | React.ReactNode - | (({ isOn }: { isOn: boolean }) => React.ReactNode); -}; + isOn?: boolean + defaultIsOn?: boolean + onIsOnChange?: (isOn: boolean | undefined) => void + children?: React.ReactNode | (({ isOn }: { isOn: boolean }) => React.ReactNode) +} -type ToggleProps = Simplify; +type ToggleProps = Simplify -export type { ToggleProps }; +export type { ToggleProps } diff --git a/src/components/tooltip/components/tooltip-content.tsx b/src/components/tooltip/components/tooltip-content.tsx index ebf0de9..2e22184 100644 --- a/src/components/tooltip/components/tooltip-content.tsx +++ b/src/components/tooltip/components/tooltip-content.tsx @@ -1,72 +1,71 @@ -"use client"; +'use client' import { - TooltipArrow as TooltipArrowPrimitive, - TooltipContent as TooltipContentPrimitive, -} from "@radix-ui/react-tooltip"; -import { cn, getOptionalObject } from "@renderui/utils"; -import React from "react"; + TooltipArrow as TooltipArrowPrimitive, + TooltipContent as TooltipContentPrimitive, +} from '@radix-ui/react-tooltip' +import { cn, getOptionalObject } from '@renderui/utils' +import React from 'react' import { - DEFAULT_SIDE_OFFSET, - DEFAULT_TOOLTIP_ARROW_CLASSNAME, - DEFAULT_TOOLTIP_CONTENT_CLASSNAME, -} from "@/components/tooltip/constants/constants"; -import { TooltipContentProps } from "@/components/tooltip/types/tooltip-content"; -import { getAnimationStyleVariables } from "@renderui/utils/get-animation-style-variables"; + DEFAULT_SIDE_OFFSET, + DEFAULT_TOOLTIP_ARROW_CLASSNAME, + DEFAULT_TOOLTIP_CONTENT_CLASSNAME, +} from '@/components/tooltip/constants/constants' +import { TooltipContentProps } from '@/components/tooltip/types/tooltip-content' +import { getAnimationStyleVariables } from '@renderui/utils/get-animation-style-variables' const TooltipContent = (props: TooltipContentProps) => { - const { - children, - className, - arrowProps, - style, - animationDuration, - animationInDuration, - animationOutDuration, - animationTimingFunction, - animationInTimingFunction, - animationOutTimingFunction, - side = "top", - hasArrow = true, - avoidCollisions = true, - sideOffset = DEFAULT_SIDE_OFFSET, - ...restProps - } = props; + const { + children, + className, + arrowProps, + style, + animationDuration, + animationInDuration, + animationOutDuration, + animationTimingFunction, + animationInTimingFunction, + animationOutTimingFunction, + side = 'top', + hasArrow = true, + avoidCollisions = true, + sideOffset = DEFAULT_SIDE_OFFSET, + ...restProps + } = props - const { className: arrowClassName, ...restArrowProps } = - getOptionalObject(arrowProps); + const { className: arrowClassName, ...restArrowProps } = getOptionalObject(arrowProps) - return ( - - {children} - {hasArrow ? ( - - ) : null} - - ); -}; + return ( + + {children} + {hasArrow ? ( + + ) : null} + + ) +} -export { TooltipContent }; +export { TooltipContent } diff --git a/src/components/tooltip/components/tooltip-trigger.tsx b/src/components/tooltip/components/tooltip-trigger.tsx index aa296bd..8d7f674 100644 --- a/src/components/tooltip/components/tooltip-trigger.tsx +++ b/src/components/tooltip/components/tooltip-trigger.tsx @@ -1,44 +1,44 @@ -"use client"; +'use client' -import { TooltipTrigger as TooltipTriggerPrimitive } from "@radix-ui/react-tooltip"; -import { chain, cx } from "@renderui/utils"; -import React from "react"; +import { TooltipTrigger as TooltipTriggerPrimitive } from '@radix-ui/react-tooltip' +import { chain, cx } from '@renderui/utils' +import React from 'react' -import { Button } from "@/components/button"; -import { DEFAULT_TOOLTIP_TRIGGER_CLASSNAME } from "@/components/tooltip/constants/constants"; -import { TooltipTriggerProps } from "@/components/tooltip/types/tooltip-trigger"; +import { Button } from '@/components/button' +import { DEFAULT_TOOLTIP_TRIGGER_CLASSNAME } from '@/components/tooltip/constants/constants' +import { TooltipTriggerProps } from '@/components/tooltip/types/tooltip-trigger' const TooltipTrigger = (props: TooltipTriggerProps) => { - const { - className, - onMouseEnter, - onMouseLeave, - hasRipple = false, - hasDefaultPressedStyles = false, - variant = "plain", - color = "mode-accent", - ...restProps - } = props; + const { + className, + onMouseEnter, + onMouseLeave, + hasRipple = false, + hasDefaultPressedStyles = false, + variant = 'plain', + color = 'mode-accent', + ...restProps + } = props - /* aria hover event not always firing in combination with radix asChild, track manually with native event */ - const [isHovered, setIsHovered] = React.useState(false); + /* aria hover event not always firing in combination with radix asChild, track manually with native event */ + const [isHovered, setIsHovered] = React.useState(false) - return ( - -