Skip to content

Commit

Permalink
TEC-4386: Radio Tag component (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsalmeida authored Apr 15, 2024
1 parent fda9a3f commit 449536e
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chardonnay",
"version": "1.0.24",
"version": "1.0.25",
"description": "A mobile first frontend framework made with wine",
"homepage": "https://vissimo-group.github.io/chardonnay/",
"main": "./dist/index.js",
Expand Down
61 changes: 61 additions & 0 deletions src/components/RadioTag/RadioTagContainer/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from '@storybook/react'
import { RadioTagContainer } from '.'
import { RadioTagLabel } from '../RadioTagLabel'
import { RadioTagInput } from '../RadioTagInput'

const meta: Meta<typeof RadioTagContainer> = {
component: RadioTagContainer,
tags: ['autodocs'],
argTypes: {
width: {
control: 'text',
description: 'Container width. If no value was set, fit-content.',
},
},
}

export default meta
type Story = StoryObj<typeof RadioTagContainer>

export const Default: Story = {
render: (args) => (
<RadioTagContainer {...args}>
<RadioTagInput id="one" name="my-radio-tag" />
<RadioTagLabel htmlFor="one">Option One</RadioTagLabel>

<RadioTagInput id="two" name="my-radio-tag" />
<RadioTagLabel htmlFor="two">Option Two</RadioTagLabel>

<RadioTagInput id="three" name="my-radio-tag" />
<RadioTagLabel htmlFor="three">Option Three</RadioTagLabel>

<RadioTagInput id="four" name="my-radio-tag" />
<RadioTagLabel htmlFor="four">Option Four</RadioTagLabel>

<RadioTagInput id="five" name="my-radio-tag" />
<RadioTagLabel htmlFor="five">Option Five</RadioTagLabel>
</RadioTagContainer>
),
}

export const WithFixedWidth: Story = {
args: { width: '300px' },
render: (args) => (
<RadioTagContainer {...args}>
<RadioTagInput id="one" name="my-radio-tag-ii" />
<RadioTagLabel htmlFor="one">Option One</RadioTagLabel>

<RadioTagInput id="two" name="my-radio-tag-ii" />
<RadioTagLabel htmlFor="two">Option Two</RadioTagLabel>

<RadioTagInput id="three" name="my-radio-tag-ii" />
<RadioTagLabel htmlFor="three">Option Three</RadioTagLabel>

<RadioTagInput id="four" name="my-radio-tag-ii" />
<RadioTagLabel htmlFor="four">Option Four</RadioTagLabel>

<RadioTagInput id="five" name="my-radio-tag-ii" />
<RadioTagLabel htmlFor="five">Option Five</RadioTagLabel>
</RadioTagContainer>
),
}
10 changes: 10 additions & 0 deletions src/components/RadioTag/RadioTagContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RadioTagContainerStyled } from './style'
import { RadioTagContainerProps } from './type'

const RadioTagContainer = ({ children, width }: RadioTagContainerProps) => {
return (
<RadioTagContainerStyled width={width}>{children}</RadioTagContainerStyled>
)
}

export { RadioTagContainer }
11 changes: 11 additions & 0 deletions src/components/RadioTag/RadioTagContainer/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styled from 'styled-components'

const RadioTagContainerStyled = styled.div<{ width?: string }>`
width: ${(props) => (props.width ? props.width : 'fit-content')};
display: flex;
gap: 0.5rem;
overflow-x: auto;
scroll-snap-type: x mandatory;
`

export { RadioTagContainerStyled }
6 changes: 6 additions & 0 deletions src/components/RadioTag/RadioTagContainer/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type RadioTagContainerProps = {
children?: React.ReactNode
width?: string
}

export type { RadioTagContainerProps }
3 changes: 3 additions & 0 deletions src/components/RadioTag/RadioTagInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RadioTagInputStyled } from './style'

export { RadioTagInputStyled as RadioTagInput }
10 changes: 10 additions & 0 deletions src/components/RadioTag/RadioTagInput/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import styled from 'styled-components'

const RadioTagInputStyled = styled.input.attrs({ type: 'radio' })`
position: absolute;
opacity: 0;
width: 0;
height: 0;
`

export { RadioTagInputStyled }
135 changes: 135 additions & 0 deletions src/components/RadioTag/RadioTagLabel/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import type { Meta, StoryObj } from '@storybook/react'
import { RadioTagLabel } from '.'
import { RadioTagInput } from '../RadioTagInput'

const meta: Meta<typeof RadioTagLabel> = {
component: RadioTagLabel,
tags: ['autodocs'],
argTypes: {
width: {
control: 'text',
description: 'Label width. If no value was set, fit-content.',
},
fontSize: {
control: 'text',
description: 'Font size of the label. Default value "1rem"',
},
},
parameters: {
docs: {
controls: { exclude: ['ref', 'theme', 'as', 'forwardedAs'] },
},
},
decorators: [
(Story) => (
<div style={{ display: 'flex', gap: '1rem' }}>
<Story />
</div>
),
],
}

export default meta
type Story = StoryObj<typeof RadioTagLabel>

export const Checked: Story = {
args: { width: '9rem', fontSize: '1rem' },
render: (args) => (
<>
<RadioTagInput checked id="one" name="my-radio-tag-v" />
<RadioTagLabel {...args} htmlFor="one">
Option One
</RadioTagLabel>

<span style={{ textWrap: 'balance', textAlign: 'center' }}>
The <strong>RadioTagLabel</strong> component must always be preceded by
a <strong>RadioTagInput</strong> for styles to be applied correctly.
</span>
</>
),
}

export const Default: Story = {
render: () => (
<>
<RadioTagInput id="one" name="my-radio-tag-iii" />
<RadioTagLabel htmlFor="one">Label One</RadioTagLabel>

<RadioTagInput id="two" name="my-radio-tag-iii" />
<RadioTagLabel htmlFor="two">Label Two</RadioTagLabel>

<RadioTagInput id="three" name="my-radio-tag-iii" />
<RadioTagLabel htmlFor="three">Label Three</RadioTagLabel>

<RadioTagInput id="four" name="my-radio-tag-iii" />
<RadioTagLabel htmlFor="four">Label Four</RadioTagLabel>

<RadioTagInput id="five" name="my-radio-tag-iii" />
<RadioTagLabel htmlFor="five">Label Three</RadioTagLabel>
</>
),
}

export const WithFixedWidth: Story = {
args: { width: '10rem' },
render: (args) => (
<>
<RadioTagInput id="one" name="my-radio-tag-iv" />
<RadioTagLabel {...args} htmlFor="one">
Option One
</RadioTagLabel>

<RadioTagInput id="two" name="my-radio-tag-iv" />
<RadioTagLabel {...args} htmlFor="two">
Option Two
</RadioTagLabel>

<RadioTagInput id="three" name="my-radio-tag-iv" />
<RadioTagLabel {...args} htmlFor="three">
Option Three
</RadioTagLabel>

<RadioTagInput id="four" name="my-radio-tag-iv" />
<RadioTagLabel {...args} htmlFor="four">
Option Four
</RadioTagLabel>

<RadioTagInput id="five" name="my-radio-tag-iv" />
<RadioTagLabel {...args} htmlFor="five">
Option Five
</RadioTagLabel>
</>
),
}

export const WithCustomFontSize: Story = {
args: { fontSize: '14px' },
render: (args) => (
<>
<RadioTagInput id="one" name="my-radio-tag-font" />
<RadioTagLabel {...args} htmlFor="one">
Label One
</RadioTagLabel>

<RadioTagInput id="two" name="my-radio-tag-font" />
<RadioTagLabel {...args} htmlFor="two">
Label Two
</RadioTagLabel>

<RadioTagInput id="three" name="my-radio-tag-font" />
<RadioTagLabel {...args} htmlFor="three">
Label Three
</RadioTagLabel>

<RadioTagInput id="four" name="my-radio-tag-font" />
<RadioTagLabel {...args} htmlFor="four">
Label Four
</RadioTagLabel>

<RadioTagInput id="five" name="my-radio-tag-font" />
<RadioTagLabel {...args} htmlFor="five">
Label Three
</RadioTagLabel>
</>
),
}
3 changes: 3 additions & 0 deletions src/components/RadioTag/RadioTagLabel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RadioTagLabelStyled } from './style'

export { RadioTagLabelStyled as RadioTagLabel }
32 changes: 32 additions & 0 deletions src/components/RadioTag/RadioTagLabel/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import styled from 'styled-components'

const RadioTagLabelStyled = styled.label<{ width?: string; fontSize?: string }>`
font-size: ${(props) => (props.fontSize ? props.fontSize : '1rem')};
width: ${(props) => (props.width ? props.width : 'fit-content')};
display: flex;
align-items: center;
justify-content: center;
min-width: fit-content;
gap: 0.5em;
border-radius: 2rem;
padding: 0.5em 1em;
background-color: ${(props) => props.theme.colors.neutral.neutral200};
color: ${(props) => props.theme.colors.neutral.neutral400};
border: 2px solid ${(props) => props.theme.colors.neutral.neutral200};
scroll-snap-align: center;
input[type='radio']:checked + & {
background-color: ${(props) => props.theme.colors.background.background200};
border: 2px solid ${(props) => props.theme.colors.action.action100};
color: ${(props) => props.theme.colors.action.action100};
}
input[type='radio']:disabled + & {
cursor: not-allowed;
}
&:not(:disabled) {
cursor: pointer;
}
`
export { RadioTagLabelStyled }

0 comments on commit 449536e

Please sign in to comment.