fix(ui): Bump cva and minor type fixes (#5818)

**What**
- Bumps `class-variance-authority` to new beta version - `cva@beta`.
- Updates all usages of `cva` to new API.
- Clear up the naming of types in `usePrompt`

**Why**
- A bug in how `class-variance-authority` exported its types mean that we were relying on patching the package to ensure that the correct types made it into the build of our UI package. This was important to ensure intellisense for component variants, such as `<Button size="large" />`. Previously in the UI monorepo, having the patch was enough to ensure that the correct types made it into the build, but that was not the case after we moved the design system to the core repo. The issue with types is fixed in the `@1` version of `cva` which is currently in beta. I have pinpointed the version to the current beta version to ensure stability despite the package currently being in beta.
This commit is contained in:
Kasper Fabricius Kristensen authored and GitHub committed 2023-12-07 20:13:44 +00:00
1 parent 85cda7ce37
commit 591ba2388d
21 files changed
+95 -172

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/ui": patch
---
fix(ui): Bump 'class-variance-authority' to 'cva@beta' and update usage to new API. Also fix the naming of usePrompt types
@@ -1,71 +0,0 @@
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 676e466a43ad8932cbb3131bb2c3dea687d47041..cbffdc5191bd8535468fdeaf68365845d15804ea 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -1,21 +1,55 @@
+import type * as CLSX from "clsx";
import clsx from "clsx";
-import type { ClassProp, ClassValue, OmitUndefined, StringToBoolean } from "./types";
-export type VariantProps<Component extends (...args: any) => any> = Omit<OmitUndefined<Parameters<Component>[0]>, "class" | "className">;
+
+type ClassPropKey = "class" | "className";
+type ClassValue = CLSX.ClassValue;
+type ClassProp =
+ | {
+ class: ClassValue;
+ className?: never;
+ }
+ | {
+ class?: never;
+ className: ClassValue;
+ }
+ | {
+ class?: never;
+ className?: never;
+ };
+type OmitUndefined<T> = T extends undefined ? never : T;
+type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
+
+export type VariantProps<Component extends (...args: any) => any> = Omit<
+ OmitUndefined<Parameters<Component>[0]>,
+ "class" | "className"
+>;
export type CxOptions = Parameters<typeof clsx>;
export type CxReturn = ReturnType<typeof clsx>;
export declare const cx: typeof clsx;
type ConfigSchema = Record<string, Record<string, ClassValue>>;
type ConfigVariants<T extends ConfigSchema> = {
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
+ [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
};
type ConfigVariantsMulti<T extends ConfigSchema> = {
- [Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined;
+ [Variant in keyof T]?:
+ | StringToBoolean<keyof T[Variant]>
+ | StringToBoolean<keyof T[Variant]>[]
+ | undefined;
};
-type Config<T> = T extends ConfigSchema ? {
- variants?: T;
- defaultVariants?: ConfigVariants<T>;
- compoundVariants?: (T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp)[];
-} : never;
-type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp;
-export declare const cva: <T>(base?: ClassValue, config?: Config<T> | undefined) => (props?: Props<T> | undefined) => string;
+type Config<T> = T extends ConfigSchema
+ ? {
+ variants?: T;
+ defaultVariants?: ConfigVariants<T>;
+ compoundVariants?: (T extends ConfigSchema
+ ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp
+ : ClassProp)[];
+ }
+ : never;
+type Props<T> = T extends ConfigSchema
+ ? ConfigVariants<T> & ClassProp
+ : ClassProp;
+export declare const cva: <T>(
+ base?: ClassValue,
+ config?: Config<T> | undefined
+) => (props?: Props<T> | undefined) => string;
export {};
+1 -2
View File
@@ -92,7 +92,6 @@
"resolutions": { "resolutions": {
"@redocly/cli/react": "^17.0.1", "@redocly/cli/react": "^17.0.1",
"@redocly/cli/react-dom": "^17.0.1", "@redocly/cli/react-dom": "^17.0.1",
"pg": "8.10.0", "pg": "8.10.0"
"class-variance-authority@0.6.1": "patch:class-variance-authority@npm:0.6.1#.yarn/patches/class-variance-authority-npm-0.6.1-22a468e86e.patch"
} }
} }
+1 -1
View File
@@ -100,9 +100,9 @@
"@radix-ui/react-tooltip": "^1.0.6", "@radix-ui/react-tooltip": "^1.0.6",
"@react-aria/datepicker": "^3.5.0", "@react-aria/datepicker": "^3.5.0",
"@react-stately/datepicker": "^3.5.0", "@react-stately/datepicker": "^3.5.0",
"class-variance-authority": "^0.6.1",
"clsx": "^1.2.1", "clsx": "^1.2.1",
"copy-to-clipboard": "^3.3.3", "copy-to-clipboard": "^3.3.3",
"cva": "1.0.0-beta.1",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"prism-react-renderer": "^2.0.6", "prism-react-renderer": "^2.0.6",
"react-currency-input-field": "^3.6.11", "react-currency-input-field": "^3.6.11",
@@ -1,14 +1,13 @@
"use client" "use client"
import * as Primitives from "@radix-ui/react-avatar" import * as Primitives from "@radix-ui/react-avatar"
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const avatarVariants = cva( const avatarVariants = cva({
"border-ui-border-strong flex shrink-0 items-center justify-center overflow-hidden border", base: "border-ui-border-strong flex shrink-0 items-center justify-center overflow-hidden border",
{
variants: { variants: {
variant: { variant: {
squared: "rounded-lg", squared: "rounded-lg",
@@ -23,10 +22,10 @@ const avatarVariants = cva(
variant: "rounded", variant: "rounded",
size: "base", size: "base",
}, },
} })
)
const innerVariants = cva("aspect-square object-cover object-center", { const innerVariants = cva({
base: "aspect-square object-cover object-center",
variants: { variants: {
variant: { variant: {
squared: "rounded-lg", squared: "rounded-lg",
@@ -1,10 +1,10 @@
import { Slot } from "@radix-ui/react-slot" import { Slot } from "@radix-ui/react-slot"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const badgeColorVariants = cva("", { const badgeColorVariants = cva({
variants: { variants: {
color: { color: {
green: green:
@@ -23,7 +23,8 @@ const badgeColorVariants = cva("", {
}, },
}) })
const badgeSizeVariants = cva("inline-flex items-center gap-x-0.5 border", { const badgeSizeVariants = cva({
base: "inline-flex items-center gap-x-0.5 border",
variants: { variants: {
size: { size: {
small: "txt-compact-xsmall-plus px-1.5", small: "txt-compact-xsmall-plus px-1.5",
@@ -1,17 +1,16 @@
import { Slot } from "@radix-ui/react-slot" import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
import { Spinner } from "@medusajs/icons" import { Spinner } from "@medusajs/icons"
const buttonVariants = cva( const buttonVariants = cva({
clx( base: clx(
"transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none", "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none",
"disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden", "disabled:bg-ui-bg-disabled disabled:border-ui-border-base disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral disabled:after:hidden",
"after:transition-fg after:absolute after:inset-0 after:content-['']" "after:transition-fg after:absolute after:inset-0 after:content-['']"
), ),
{
variants: { variants: {
variant: { variant: {
primary: clx( primary: clx(
@@ -51,8 +50,7 @@ const buttonVariants = cva(
size: "base", size: "base",
variant: "primary", variant: "primary",
}, },
} })
)
interface ButtonProps interface ButtonProps
extends React.ComponentPropsWithoutRef<"button">, extends React.ComponentPropsWithoutRef<"button">,
@@ -5,15 +5,14 @@ import Primitive from "react-currency-input-field"
import { Text } from "@/components/text" import { Text } from "@/components/text"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
const currencyInputVariants = cva( const currencyInputVariants = cva({
clx( base: clx(
"flex items-center gap-x-1", "flex items-center gap-x-1",
"bg-ui-bg-field hover:bg-ui-bg-field-hover shadow-buttons-neutral placeholder-ui-fg-muted text-ui-fg-base transition-fg relative w-full rounded-md", "bg-ui-bg-field hover:bg-ui-bg-field-hover shadow-buttons-neutral placeholder-ui-fg-muted text-ui-fg-base transition-fg relative w-full rounded-md",
"focus-within:shadow-borders-interactive-with-active" "focus-within:shadow-borders-interactive-with-active"
), ),
{
variants: { variants: {
size: { size: {
base: "txt-compact-medium h-10 px-3", base: "txt-compact-medium h-10 px-3",
@@ -23,8 +22,7 @@ const currencyInputVariants = cva(
defaultVariants: { defaultVariants: {
size: "base", size: "base",
}, },
} })
)
interface CurrencyInputProps interface CurrencyInputProps
extends Omit< extends Omit<
@@ -13,17 +13,16 @@ import { TimeInput } from "@/components/time-input"
import type { DateRange } from "@/types" import type { DateRange } from "@/types"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
import { isBrowserLocaleClockType24h } from "@/utils/is-browser-locale-hour-cycle-24h" import { isBrowserLocaleClockType24h } from "@/utils/is-browser-locale-hour-cycle-24h"
import { cva } from "class-variance-authority" import { cva } from "cva"
const displayVariants = cva( const displayVariants = cva({
clx( base: clx(
"text-ui-fg-base bg-ui-bg-field transition-fg shadow-buttons-neutral flex w-full items-center gap-x-2 rounded-md outline-none", "text-ui-fg-base bg-ui-bg-field transition-fg shadow-buttons-neutral flex w-full items-center gap-x-2 rounded-md outline-none",
"hover:bg-ui-bg-field-hover", "hover:bg-ui-bg-field-hover",
"focus:shadow-borders-interactive-with-active data-[state=open]:shadow-borders-interactive-with-active", "focus:shadow-borders-interactive-with-active data-[state=open]:shadow-borders-interactive-with-active",
"disabled:bg-ui-bg-disabled disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral", "disabled:bg-ui-bg-disabled disabled:text-ui-fg-disabled disabled:shadow-buttons-neutral",
"aria-[invalid=true]:!shadow-borders-error" "aria-[invalid=true]:!shadow-borders-error"
), ),
{
variants: { variants: {
size: { size: {
base: "txt-compact-medium h-10 px-3 py-2.5", base: "txt-compact-medium h-10 px-3 py-2.5",
@@ -33,8 +32,7 @@ const displayVariants = cva(
defaultVariants: { defaultVariants: {
size: "base", size: "base",
}, },
} })
)
const Display = React.forwardRef< const Display = React.forwardRef<
HTMLButtonElement, HTMLButtonElement,
@@ -1,9 +1,10 @@
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const headingVariants = cva("font-sans font-medium", { const headingVariants = cva({
base: "font-sans font-medium",
variants: { variants: {
level: { level: {
h1: "h1-core", h1: "h1-core",
@@ -1,12 +1,11 @@
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { ExclamationCircleSolid } from "@medusajs/icons" import { ExclamationCircleSolid } from "@medusajs/icons"
import { clx } from "../../utils/clx" import { clx } from "../../utils/clx"
const hintVariants = cva( const hintVariants = cva({
"txt-compact-xsmall inline-flex items-center gap-x-2", base: "txt-compact-xsmall inline-flex items-center gap-x-2",
{
variants: { variants: {
variant: { variant: {
info: "text-ui-fg-subtle", info: "text-ui-fg-subtle",
@@ -16,8 +15,7 @@ const hintVariants = cva(
defaultVariants: { defaultVariants: {
variant: "info", variant: "info",
}, },
} })
)
type HintProps = VariantProps<typeof hintVariants> & type HintProps = VariantProps<typeof hintVariants> &
React.ComponentPropsWithoutRef<"span"> React.ComponentPropsWithoutRef<"span">
@@ -1,21 +1,19 @@
import { Slot } from "@radix-ui/react-slot" import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "cva"
import * as React from "react" import * as React from "react"
import { badgeColorVariants } from "@/components/badge" import { badgeColorVariants } from "@/components/badge"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const iconBadgeVariants = cva( const iconBadgeVariants = cva({
"flex items-center justify-center overflow-hidden rounded-md border", base: "flex items-center justify-center overflow-hidden rounded-md border",
{
variants: { variants: {
size: { size: {
base: "h-6 w-6", base: "h-6 w-6",
large: "h-7 w-7", large: "h-7 w-7",
}, },
}, },
} })
)
interface IconBadgeProps interface IconBadgeProps
extends Omit<React.ComponentPropsWithoutRef<"span">, "color">, extends Omit<React.ComponentPropsWithoutRef<"span">, "color">,
@@ -1,16 +1,15 @@
import { Spinner } from "@medusajs/icons" import { Spinner } from "@medusajs/icons"
import { Slot } from "@radix-ui/react-slot" import { Slot } from "@radix-ui/react-slot"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const iconButtonVariants = cva( const iconButtonVariants = cva({
clx( base: clx(
"transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none", "transition-fg relative inline-flex w-fit items-center justify-center overflow-hidden rounded-md outline-none",
"disabled:bg-ui-bg-disabled disabled:shadow-buttons-neutral disabled:text-ui-fg-disabled disabled:after:hidden" "disabled:bg-ui-bg-disabled disabled:shadow-buttons-neutral disabled:text-ui-fg-disabled disabled:after:hidden"
), ),
{
variants: { variants: {
variant: { variant: {
primary: clx( primary: clx(
@@ -38,8 +37,7 @@ const iconButtonVariants = cva(
variant: "primary", variant: "primary",
size: "base", size: "base",
}, },
} })
)
interface IconButtonProps interface IconButtonProps
extends React.ComponentPropsWithoutRef<"button">, extends React.ComponentPropsWithoutRef<"button">,
@@ -1,7 +1,7 @@
"use client" "use client"
import { Eye, EyeSlash, MagnifyingGlassMini } from "@medusajs/icons" import { Eye, EyeSlash, MagnifyingGlassMini } from "@medusajs/icons"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
@@ -13,12 +13,11 @@ const inputBaseStyles = clx(
"aria-[invalid=true]:!shadow-borders-error invalid:!shadow-borders-error" "aria-[invalid=true]:!shadow-borders-error invalid:!shadow-borders-error"
) )
const inputVariants = cva( const inputVariants = cva({
clx( base: clx(
inputBaseStyles, inputBaseStyles,
"[&::--webkit-search-cancel-button]:hidden [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden" "[&::--webkit-search-cancel-button]:hidden [&::-webkit-search-cancel-button]:hidden [&::-webkit-search-decoration]:hidden"
), ),
{
variants: { variants: {
size: { size: {
base: "txt-compact-medium h-10 px-3 py-[9px]", base: "txt-compact-medium h-10 px-3 py-[9px]",
@@ -28,8 +27,7 @@ const inputVariants = cva(
defaultVariants: { defaultVariants: {
size: "base", size: "base",
}, },
} })
)
const Input = React.forwardRef< const Input = React.forwardRef<
HTMLInputElement, HTMLInputElement,
@@ -1,12 +1,13 @@
"use client" "use client"
import * as Primitives from "@radix-ui/react-label" import * as Primitives from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority" import { cva, type VariantProps } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const labelVariants = cva("font-sans", { const labelVariants = cva({
base: "font-sans",
variants: { variants: {
size: { size: {
xsmall: "txt-compact-xsmall", xsmall: "txt-compact-xsmall",
@@ -2,7 +2,7 @@
import { ChevronUpDown, EllipseMiniSolid } from "@medusajs/icons" import { ChevronUpDown, EllipseMiniSolid } from "@medusajs/icons"
import * as SelectPrimitive from "@radix-ui/react-select" import * as SelectPrimitive from "@radix-ui/react-select"
import { cva } from "class-variance-authority" import { cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
@@ -40,8 +40,8 @@ const Group = SelectPrimitive.Group
const Value = SelectPrimitive.Value const Value = SelectPrimitive.Value
const triggerVariants = cva( const triggerVariants = cva({
clx( base: clx(
"bg-ui-bg-field txt-compact-medium shadow-buttons-neutral transition-fg flex w-full select-none items-center justify-between rounded-md outline-none", "bg-ui-bg-field txt-compact-medium shadow-buttons-neutral transition-fg flex w-full select-none items-center justify-between rounded-md outline-none",
"data-[placeholder]:text-ui-fg-muted text-ui-fg-base", "data-[placeholder]:text-ui-fg-muted text-ui-fg-base",
"hover:bg-ui-bg-field-hover", "hover:bg-ui-bg-field-hover",
@@ -51,15 +51,13 @@ const triggerVariants = cva(
"disabled:!bg-ui-bg-disabled disabled:!text-ui-fg-disabled", "disabled:!bg-ui-bg-disabled disabled:!text-ui-fg-disabled",
"group/trigger" "group/trigger"
), ),
{
variants: { variants: {
size: { size: {
base: "h-10 px-3 py-[9px]", base: "h-10 px-3 py-[9px]",
small: "h-8 px-2 py-[5px]", small: "h-8 px-2 py-[5px]",
}, },
}, },
} })
)
const Trigger = React.forwardRef< const Trigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>, React.ElementRef<typeof SelectPrimitive.Trigger>,
@@ -1,14 +1,13 @@
"use client" "use client"
import * as Primitives from "@radix-ui/react-switch" import * as Primitives from "@radix-ui/react-switch"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const switchVariants = cva( const switchVariants = cva({
"bg-ui-bg-switch-off hover:bg-ui-bg-switch-off-hover data-[state=unchecked]:hover:after:bg-switch-off-hover-gradient before:shadow-details-switch-background focus:shadow-details-switch-background-focus data-[state=checked]:bg-ui-bg-interactive disabled:!bg-ui-bg-disabled group relative inline-flex items-center rounded-full outline-none transition-all before:absolute before:inset-0 before:rounded-full before:content-[''] after:absolute after:inset-0 after:rounded-full after:content-[''] disabled:cursor-not-allowed", base: "bg-ui-bg-switch-off hover:bg-ui-bg-switch-off-hover data-[state=unchecked]:hover:after:bg-switch-off-hover-gradient before:shadow-details-switch-background focus:shadow-details-switch-background-focus data-[state=checked]:bg-ui-bg-interactive disabled:!bg-ui-bg-disabled group relative inline-flex items-center rounded-full outline-none transition-all before:absolute before:inset-0 before:rounded-full before:content-[''] after:absolute after:inset-0 after:rounded-full after:content-[''] disabled:cursor-not-allowed",
{
variants: { variants: {
size: { size: {
small: "h-[16px] w-[28px]", small: "h-[16px] w-[28px]",
@@ -18,12 +17,10 @@ const switchVariants = cva(
defaultVariants: { defaultVariants: {
size: "base", size: "base",
}, },
} })
)
const thumbVariants = cva( const thumbVariants = cva({
"bg-ui-fg-on-color shadow-details-switch-handle group-disabled:bg-ui-fg-disabled pointer-events-none h-[14px] w-[14px] rounded-full transition-all group-disabled:shadow-none", base: "bg-ui-fg-on-color shadow-details-switch-handle group-disabled:bg-ui-fg-disabled pointer-events-none h-[14px] w-[14px] rounded-full transition-all group-disabled:shadow-none",
{
variants: { variants: {
size: { size: {
small: small:
@@ -34,8 +31,7 @@ const thumbVariants = cva(
defaultVariants: { defaultVariants: {
size: "base", size: "base",
}, },
} })
)
interface SwitchProps interface SwitchProps
extends Omit< extends Omit<
@@ -1,10 +1,10 @@
import { Slot } from "@radix-ui/react-slot" import { Slot } from "@radix-ui/react-slot"
import { VariantProps, cva } from "class-variance-authority" import { VariantProps, cva } from "cva"
import * as React from "react" import * as React from "react"
import { clx } from "@/utils/clx" import { clx } from "@/utils/clx"
const textVariants = cva("", { const textVariants = cva({
variants: { variants: {
size: { size: {
xsmall: "", xsmall: "",
@@ -6,7 +6,7 @@ import { Input } from "@/components/input"
import { Label } from "@/components/label" import { Label } from "@/components/label"
import { Prompt } from "@/components/prompt" import { Prompt } from "@/components/prompt"
export type DialogProps = { export type RenderPromptProps = {
open: boolean open: boolean
title: string title: string
description: string description: string
@@ -17,7 +17,7 @@ export type DialogProps = {
onCancel: () => void onCancel: () => void
} }
const Dialog = ({ export const RenderPrompt = ({
open, open,
title, title,
description, description,
@@ -26,7 +26,7 @@ const Dialog = ({
confirmText = "Confirm", confirmText = "Confirm",
onConfirm, onConfirm,
onCancel, onCancel,
}: DialogProps) => { }: RenderPromptProps) => {
const [userInput, setUserInput] = React.useState("") const [userInput, setUserInput] = React.useState("")
const handleUserInput = (event: React.ChangeEvent<HTMLInputElement>) => { const handleUserInput = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -108,5 +108,3 @@ const Dialog = ({
</Prompt> </Prompt>
) )
} }
export default Dialog
@@ -2,14 +2,12 @@
import * as React from "react" import * as React from "react"
import { createRoot } from "react-dom/client" import { createRoot } from "react-dom/client"
import { DialogProps } from "./dialog" import { RenderPrompt, RenderPromptProps } from "./render-prompt"
import Dialog from "./dialog" type UsePromptProps = Omit<RenderPromptProps, "onConfirm" | "onCancel" | "open">
type PromptProps = Omit<DialogProps, "onConfirm" | "onCancel" | "open">
const usePrompt = () => { const usePrompt = () => {
const dialog = async (props: PromptProps): Promise<boolean> => { const prompt = async (props: UsePromptProps): Promise<boolean> => {
return new Promise((resolve) => { return new Promise((resolve) => {
let open = true let open = true
@@ -29,7 +27,7 @@ const usePrompt = () => {
const render = () => { const render = () => {
mountRoot.render( mountRoot.render(
<Dialog <RenderPrompt
open={open} open={open}
onConfirm={onConfirm} onConfirm={onConfirm}
onCancel={onCancel} onCancel={onCancel}
@@ -42,7 +40,7 @@ const usePrompt = () => {
}) })
} }
return dialog return prompt
} }
export { usePrompt } export { usePrompt }
+23 -11
View File
@@ -8020,9 +8020,9 @@ __metadata:
"@vitest/coverage-v8": ^0.32.2 "@vitest/coverage-v8": ^0.32.2
autoprefixer: ^10.4.14 autoprefixer: ^10.4.14
chromatic: ^6.20.0 chromatic: ^6.20.0
class-variance-authority: ^0.6.1
clsx: ^1.2.1 clsx: ^1.2.1
copy-to-clipboard: ^3.3.3 copy-to-clipboard: ^3.3.3
cva: 1.0.0-beta.1
date-fns: ^2.30.0 date-fns: ^2.30.0
eslint: ^7.32.0 eslint: ^7.32.0
eslint-plugin-storybook: ^0.6.12 eslint-plugin-storybook: ^0.6.12
@@ -21444,15 +21444,6 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"class-variance-authority@npm:^0.6.1":
version: 0.6.1
resolution: "class-variance-authority@npm:0.6.1"
dependencies:
clsx: 1.2.1
checksum: 0685b1a92d97fbb26b1031a9dcb9d419c4bbb163aa20a6025a11f3a92ebd6209da277c63f789b294d890a0d500558de285fd842068c824d40b5beda97e01aa1a
languageName: node
linkType: hard
"classnames@npm:^2.2.6, classnames@npm:^2.3.1": "classnames@npm:^2.2.6, classnames@npm:^2.3.1":
version: 2.3.2 version: 2.3.2
resolution: "classnames@npm:2.3.2" resolution: "classnames@npm:2.3.2"
@@ -21734,7 +21725,14 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"clsx@npm:1.2.1, clsx@npm:^1.1.0, clsx@npm:^1.1.1, clsx@npm:^1.2.1": "clsx@npm:2.0.0":
version: 2.0.0
resolution: "clsx@npm:2.0.0"
checksum: c09f43b3144a0b7826b6b11b6a111b2c7440831004eecc02d333533c5e58ef0aa5f2dce071d3b25fbb8c8ea97b45df96c74bcc1d51c8c2027eb981931107b0cd
languageName: node
linkType: hard
"clsx@npm:^1.1.0, clsx@npm:^1.1.1, clsx@npm:^1.2.1":
version: 1.2.1 version: 1.2.1
resolution: "clsx@npm:1.2.1" resolution: "clsx@npm:1.2.1"
checksum: 34dead8bee24f5e96f6e7937d711978380647e936a22e76380290e35486afd8634966ce300fc4b74a32f3762c7d4c0303f442c3e259f4ce02374eb0c82834f27 checksum: 34dead8bee24f5e96f6e7937d711978380647e936a22e76380290e35486afd8634966ce300fc4b74a32f3762c7d4c0303f442c3e259f4ce02374eb0c82834f27
@@ -23175,6 +23173,20 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"cva@npm:1.0.0-beta.1":
version: 1.0.0-beta.1
resolution: "cva@npm:1.0.0-beta.1"
dependencies:
clsx: 2.0.0
peerDependencies:
typescript: ">= 4.5.5 < 6"
peerDependenciesMeta:
typescript:
optional: true
checksum: 0ac27613b156d0ff6b1450c3257c1b98356865366165cb973748a102ed576dc07824cd098b23da6e24155d3b732d6222b4fa83cff85fbd2df3924a5b425bfbde
languageName: node
linkType: hard
"cyclist@npm:^1.0.1": "cyclist@npm:^1.0.1":
version: 1.0.2 version: 1.0.2
resolution: "cyclist@npm:1.0.2" resolution: "cyclist@npm:1.0.2"