Skip to content

Commit

Permalink
Merge pull request #264 from omnifed/262-feature-add-consistent-types…
Browse files Browse the repository at this point in the history
…-in-react

262 feature add consistent types in react
  • Loading branch information
caseybaggz committed Jul 10, 2024
2 parents e9386b3 + 4983f56 commit 782341c
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/app/react/tags/components/closable-tag-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function ClosableTagPreview(props: TagPreviewProps) {
}, [])

return (
<Tag shape="pill" onClick={handleClick}>
<Tag shape="pill" onClick={handleClick} usage="filled">
Closable
</Tag>
)
Expand Down
8 changes: 4 additions & 4 deletions docs/app/react/tags/components/tag-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function BasicTagPreview() {

export function OutlineTagPreview() {
return (
<Tag shape="rounded" usage="outline">
Outline
<Tag shape="rounded" usage="outlined">
Outlined
</Tag>
)
}
Expand Down Expand Up @@ -184,13 +184,13 @@ function MatchTagPalettePreview(props: MatchTagProps) {
)
case 'info':
return (
<Tag palette="info" shape="rounded" usage="outline">
<Tag palette="info" shape="rounded" usage="outlined">
Info
</Tag>
)
case 'success':
return (
<Tag palette="success" shape="rounded" usage="outline">
<Tag palette="success" shape="rounded" usage="outlined">
Success
</Tag>
)
Expand Down
6 changes: 3 additions & 3 deletions docs/app/react/tags/dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ function BasicTagPreview() {
```
</CodePreview>

### Outline
### Outlined

<CodePreview preview={<OutlineTagPreview />}>
```tsx title="tag.tsx"
import { Tag } from '@cerberus-design/react'

function OutlineTagPreview() {
function OutlinedTagPreview() {
return (
<Tag shape="rounded" usage="outline">
Outline
Expand Down Expand Up @@ -204,7 +204,7 @@ function CustomTagPreview() {
export interface TagProps extends HTMLAttributes<HTMLSpanElement> {
palette?: Sentiment
shape?: 'rounded' | 'pill'
usage?: 'filled' | 'outline'
usage?: 'filled' | 'outlined'
}
export interface ClickableTagProps extends HTMLAttributes<HTMLSpanElement> {
shape?: 'pill'
Expand Down
2 changes: 1 addition & 1 deletion figma/src/tag.figma.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const props = {
}),
usage: figma.enum('Usage', {
filled: 'filled',
outlined: 'outline',
outlined: 'outlined',
}),
// Figma specific
text: figma.textContent('label'),
Expand Down
2 changes: 1 addition & 1 deletion packages/panda-preset/src/recipes/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const tag: RecipeConfig<RecipeVariantRecord> = defineRecipe({
palette: tagPalettes,
usage: {
filled: filledUsage,
outline: {
outlined: {
bgColor: 'inherit',
border: '1.5px solid',
borderColor: 'colorPalette.border.initial',
Expand Down
9 changes: 3 additions & 6 deletions packages/react/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type { ButtonHTMLAttributes } from 'react'
import { cx } from '@cerberus/styled-system/css'
import { cx, type RecipeVariantProps } from '@cerberus/styled-system/css'
import { button } from '@cerberus/styled-system/recipes'

/**
* This module contains the Button component.
* @module
*/

export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
palette?: 'action' | 'danger'
usage?: 'filled' | 'outlined' | 'text'
shape?: 'sharp' | 'rounded'
}
export type ButtonProps = ButtonHTMLAttributes<HTMLButtonElement> &
RecipeVariantProps<typeof button>

/**
* A component that allows the user to perform actions
Expand Down
11 changes: 4 additions & 7 deletions packages/react/src/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import type { ButtonHTMLAttributes } from 'react'
import { cx } from '@cerberus/styled-system/css'
import { cx, type RecipeVariantProps } from '@cerberus/styled-system/css'
import { iconButton } from '@cerberus/styled-system/recipes'
import type { ButtonProps } from './Button'

/**
* This module contains the Icon Button component.
* @module
*/

export interface IconButtonProps
export interface IconButtonRawProps
extends ButtonHTMLAttributes<HTMLButtonElement> {
ariaLabel: string
palette?: ButtonProps['palette']
usage?: ButtonProps['usage']
shape?: 'circle'
size?: 'sm' | 'lg'
tooltipPosition?: 'top' | 'bottom' | 'left' | 'right'
}
export type IconButtonRecipeProps = RecipeVariantProps<typeof iconButton>
export type IconButtonProps = IconButtonRawProps & IconButtonRecipeProps

/**
* A component that allows the user to perform actions using an icon
Expand Down
37 changes: 20 additions & 17 deletions packages/react/src/components/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,42 @@ import { Close } from '@cerberus/icons'
import { Show } from './Show'
import { css, cx } from '@cerberus/styled-system/css'
import { iconButton, tag } from '@cerberus/styled-system/recipes'
import type { ConditionalValue } from '@cerberus/styled-system/types'
import type {
ConditionalValue,
RecipeVariantProps,
} from '@cerberus/styled-system/types'

/**
* This module contains the tag component.
* @module
*/

export type NonActionablePalette = ConditionalValue<
'neutral' | 'info' | 'success' | 'warning' | 'danger'
>
export interface TagProps extends HTMLAttributes<HTMLSpanElement> {
palette?: NonActionablePalette
shape?: 'rounded' | 'pill'
usage?: 'filled' | 'outline'
}
export interface ClickableTagProps extends HTMLAttributes<HTMLSpanElement> {
palette?: NonActionablePalette
shape?: 'pill'
export type TagRecipeProps = RecipeVariantProps<typeof tag>
export type StaticTagProps = HTMLAttributes<HTMLSpanElement> &
TagRecipeProps & {
onClick?: never
}
export type ClickableTagProps = HTMLAttributes<HTMLSpanElement> & {
palette?: ConditionalValue<
'neutral' | 'info' | 'success' | 'warning' | 'danger'
>
onClick: () => void
usage?: 'filled'
shape: 'pill'
usage: 'filled'
}
export type TagProps = StaticTagProps | ClickableTagProps

/**
* The Tag component is used to display a meta descriptions.
* @definition [Tag docs](https://cerberus.digitalu.design/react/tags)
* @example
* ```tsx
* <Tag>Tag</Tag>
* ```
*/
export function Tag(
props: PropsWithChildren<TagProps | ClickableTagProps>,
): JSX.Element {
const { palette, shape: initShape, onClick, usage, ...nativeProps } = props
export function Tag(props: PropsWithChildren<TagProps>): JSX.Element {
const { shape: initShape, onClick, usage, ...nativeProps } = props
const palette = props?.palette ?? 'neutral'
const isClosable = Boolean(onClick)
const shape = isClosable ? 'pill' : initShape
const closableStyles = isClosable
Expand Down
4 changes: 2 additions & 2 deletions tests/panda-preset/recipes/tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('tag recipe', () => {
})
})

test('should have an outline usage variant', () => {
expect(tag.variants?.usage.outline).toMatchObject({
test('should have an outlined usage variant', () => {
expect(tag.variants?.usage.outlined).toMatchObject({
bgColor: 'inherit',
border: '1.5px solid',
borderColor: 'colorPalette.border.initial',
Expand Down
10 changes: 5 additions & 5 deletions tests/react/components/tag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ describe('Tag', () => {
).toBeTrue()
})

test('should render an outline tag', () => {
render(<Tag usage="outline">it works</Tag>)
test('should render an outlined tag', () => {
render(<Tag usage="outlined">it works</Tag>)
expect(
screen
.getByText(/it works/i)
.classList.contains('cerberus-tag--usage_outline'),
.classList.contains('cerberus-tag--usage_outlined'),
).toBeTrue()
})

Expand All @@ -59,7 +59,7 @@ describe('Tag', () => {

test('should render a pill when onClick is provided', () => {
render(
<Tag shape="rounded" onClick={jest.fn()}>
<Tag shape="pill" onClick={jest.fn()} usage="filled">
it works
</Tag>,
)
Expand All @@ -82,7 +82,7 @@ describe('Tag', () => {
test('should render a tag with a close button', async () => {
const onClick = jest.fn()
render(
<Tag shape="pill" onClick={onClick}>
<Tag shape="pill" onClick={onClick} usage="filled">
it works
</Tag>,
)
Expand Down

0 comments on commit 782341c

Please sign in to comment.