diff --git a/packages/components/icon/src/Icon.doc.mdx b/packages/components/icon/src/Icon.doc.mdx index 4d093525f..bdcfcfbb5 100644 --- a/packages/components/icon/src/Icon.doc.mdx +++ b/packages/components/icon/src/Icon.doc.mdx @@ -13,14 +13,14 @@ Accessible icon wrapper ## Install -``` +```sh npm install @spark-ui/icon ``` ## Import -``` -import { Icon } from "@spark-ui/icon" +```tsx +import { Icon } from '@spark-ui/icon' ``` ## Props @@ -33,13 +33,13 @@ import { Icon } from "@spark-ui/icon" ## Sizes -Use `size` prop to change the size of the icon. +Use `size` prop to change the size of the icon. If `current` is set the current font size will be used. ## Colors -Use a utility text color class to change the color of the icon. +Use `intent` prop to change the color of the icon. If `current` is set the current font color will be used. diff --git a/packages/components/icon/src/Icon.stories.tsx b/packages/components/icon/src/Icon.stories.tsx index a4114622e..ff87b38a2 100644 --- a/packages/components/icon/src/Icon.stories.tsx +++ b/packages/components/icon/src/Icon.stories.tsx @@ -1,4 +1,5 @@ import { Meta, StoryFn } from '@storybook/react' +import { ComponentProps } from 'react' import { Icon } from '.' @@ -17,7 +18,7 @@ export const Default: StoryFn = _args => ( ) -const sizes = ['sm', 'md', 'lg'] as const +const sizes: ComponentProps['size'][] = ['sm', 'md', 'lg'] export const Sizes: StoryFn = _args => ( <> @@ -29,19 +30,37 @@ export const Sizes: StoryFn = _args => ( ))} + + + + + + ) +const intents: ComponentProps['intent'][] = [ + 'primary', + 'secondary', + 'success', + 'alert', + 'error', + 'info', + 'neutral', +] + export const Colors: StoryFn = _args => (
- - - - - + {intents.map(intent => ( + + + + + + ))} - + diff --git a/packages/components/icon/src/Icon.tsx b/packages/components/icon/src/Icon.tsx index b25d2b14a..69a4001d6 100644 --- a/packages/components/icon/src/Icon.tsx +++ b/packages/components/icon/src/Icon.tsx @@ -15,13 +15,20 @@ export interface IconProps extends IconVariantsProps, React.SVGProps label?: string } -export function Icon({ label, className, size = 'md', children, ...others }: IconProps) { +export function Icon({ + label, + className, + size = 'current', + intent = 'current', + children, + ...others +}: IconProps) { const child = React.Children.only(children) return ( <> {React.cloneElement(child as React.ReactElement, { - className: iconVariants({ className, size }), + className: iconVariants({ className, size, intent }), 'aria-hidden': 'true', focusable: 'false', ...others, diff --git a/packages/components/icon/src/Icon.variants.tsx b/packages/components/icon/src/Icon.variants.tsx index 0c8491270..56c360f51 100644 --- a/packages/components/icon/src/Icon.variants.tsx +++ b/packages/components/icon/src/Icon.variants.tsx @@ -3,7 +3,18 @@ import { cva, VariantProps } from 'class-variance-authority' export const iconVariants = cva(['fill-current'], { variants: { + intent: makeVariants<'intent'>({ + current: ['text-current'], + primary: ['text-primary'], + secondary: ['text-secondary'], + success: ['text-success'], + alert: ['text-alert'], + error: ['text-error'], + info: ['text-info'], + neutral: ['text-neutral'], + }), size: makeVariants<'size'>({ + current: ['w-current', 'h-current'], sm: ['w-sz-16', 'h-sz-16'], md: ['w-sz-24', 'h-sz-24'], lg: ['w-sz-32', 'h-sz-32'],