Skip to content

Commit

Permalink
Refactor button component to use typed props
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Feb 29, 2024
1 parent d8f74e7 commit 78abbe0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ return (
<p class="a b c d">D</p>
```

## Typings
```ts
declare type Props = {
$size: 'sm' | 'md'
}

const Button = styled.button<Props>('flex', {
$size: {
sm: 'font:12 size:8x',
md: 'font:14 size:12x'
},
disabled: 'opacity:.5'
})
```

## Overview `class-variant` APIs
```ts
import cv from 'class-variant'
Expand Down
2 changes: 1 addition & 1 deletion packages/react/e2e/ApplyBasedOnPredefinedVariants.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { test, expect } from '@playwright/experimental-ct-react'
import Element from './ApplyBasedOnPredefinedVariants'

test('element', async ({ mount }) =>
await expect(await mount(<Element size="sm" disabled />))
await expect(await mount(<Element $size="sm" disabled />))
.toHaveClass('flex font:12 size:8x opacity:.5')
)
10 changes: 7 additions & 3 deletions packages/react/e2e/ApplyBasedOnPredefinedVariants.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import styled from '../src';

const Element = styled.button('flex', {
size: {
declare type Props = {
$size: 'sm' | 'md'
}

const Button = styled.button<Props>('flex', {
$size: {
sm: 'font:12 size:8x',
md: 'font:14 size:12x'
},
disabled: 'opacity:.5'
})

export default Element
export default Button

0 comments on commit 78abbe0

Please sign in to comment.