Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPHJOD-328: Update RadioButton + RadioButtonGroup styles #36

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/components/RadioButton/RadioButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';

import { RadioButton } from './RadioButton';
import { RadioButtonGroup, RadioButtonGroupProps } from './RadioButtonGroup';

const meta = {
title: 'Forms/RadioButton',
component: RadioButtonGroup,
tags: ['autodocs'],
} satisfies Meta<typeof RadioButtonGroup>;

export default meta;

type Story = StoryObj<typeof meta>;

const parameters = {
design: {
type: 'figma',
url: 'https://www.figma.com/file/6M2LrpSCcB0thlFDaQAI2J/cx_jod_client?type=design&node-id=746-43288',
},
};

const DefaultStoryRender = (props: RadioButtonGroupProps) => {
const [value, setValue] = React.useState<string>('a');
return <RadioButtonGroup {...props} value={value} onChange={setValue} />;
};
export const Default: Story = {
parameters: {
...parameters,
},
args: {
label: 'Valitse, miten haluat ryhmitellä osaamisesi.',
value: 'a',
onChange: fn(),
children: (
<>
<RadioButton label="Lähteiden mukaan" value="a" />
<RadioButton label="Teemoittain" value="b" />
<RadioButton label="Aakkosellisesti" value="c" />
</>
),
},
render: (args) => {
return <DefaultStoryRender {...args} />;
},
};
34 changes: 23 additions & 11 deletions lib/components/RadioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export interface RadioButtonProps {

export const RadioButton = ({ label, value, className }: RadioButtonProps) => {
return (
<RadioGroup.Option value={value} className={`${className ? className : ''}`.trim()}>
<RadioGroup.Option value={value} className={`${className ? className : ''} flex h-7`.trim()}>
{({ checked }) => (
<div className="flex-start flex space-x-3">
<div className="flex-start flex space-x-4">
{checked ? <CheckedIcon /> : <UncheckedIcon />}
<span className="flex items-center text-[#4D5358]">{label}</span>
<span className="flex items-center text-button-md text-primary-gray hover:text-accent hover:underline">
{label}
</span>
</div>
)}
</RadioGroup.Option>
Expand All @@ -24,20 +26,30 @@ export const RadioButton = ({ label, value, className }: RadioButtonProps) => {

const CheckedIcon = () => {
return (
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g>
<circle cx="15.6992" cy="16.1349" r="10.6992" stroke="#4D5358" strokeWidth="10" />
</g>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
className="self-center"
>
<circle cx="12.0352" cy="12.0389" r="8" className="stroke-accent" strokeWidth="8" />
</svg>
);
};

const UncheckedIcon = () => {
return (
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g>
<circle cx="15.6992" cy="16.5333" r="15.6992" fill="white" />
</g>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
className="self-center"
>
<circle cx="12.0352" cy="12.0389" r="11" className="stroke-primary-gray" strokeWidth="2" />
</svg>
);
};
2 changes: 1 addition & 1 deletion lib/components/RadioButton/RadioButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const RadioButtonGroup = ({ label, value, onChange, children, className }
onChange={onChange}
className={`${className ? className : ''} flex flex-col space-y-2`.trim()}
>
<RadioGroup.Label className="text-[#4D5358]">{label}</RadioGroup.Label>
<RadioGroup.Label className="mb-5 text-body-xs text-secondary-gray">{label}</RadioGroup.Label>
{children}
</RadioGroup>
);
Expand Down
31 changes: 15 additions & 16 deletions lib/components/RadioButton/__snapshots__/RadioButton.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,41 @@ exports[`Snapshot testing > Default 1`] = `
role="radiogroup"
>
<label
class="text-[#4D5358]"
class="mb-5 text-body-xs text-secondary-gray"
id="headlessui-label-:r1:"
role="none"
>
Label
</label>
<div
aria-checked="true"
class=""
class="flex h-7"
data-headlessui-state="checked"
id="headlessui-radiogroup-option-:r2:"
role="radio"
tabindex="0"
>
<div
class="flex-start flex space-x-3"
class="flex-start flex space-x-4"
>
<svg
class="self-center"
fill="none"
height="32"
viewBox="0 0 32 32"
width="32"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<g>
<circle
cx="15.6992"
cy="16.1349"
r="10.6992"
stroke="#4D5358"
stroke-width="10"
/>
</g>
<circle
class="stroke-accent"
cx="12.0352"
cy="12.0389"
r="8"
stroke-width="8"
/>
</svg>
<span
class="flex items-center text-[#4D5358]"
class="flex items-center text-button-md text-primary-gray hover:text-accent hover:underline"
>
A
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,41 @@ exports[`Snapshot testing > Default 1`] = `
role="radiogroup"
>
<label
class="text-[#4D5358]"
class="mb-5 text-body-xs text-secondary-gray"
id="headlessui-label-:r1:"
role="none"
>
A
</label>
<div
aria-checked="false"
class=""
class="flex h-7"
data-headlessui-state=""
id="headlessui-radiogroup-option-:r2:"
role="radio"
tabindex="0"
>
<div
class="flex-start flex space-x-3"
class="flex-start flex space-x-4"
>
<svg
class="self-center"
fill="none"
height="32"
viewBox="0 0 32 32"
width="32"
height="24"
viewBox="0 0 24 24"
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<g>
<circle
cx="15.6992"
cy="16.5333"
fill="white"
r="15.6992"
/>
</g>
<circle
class="stroke-primary-gray"
cx="12.0352"
cy="12.0389"
r="11"
stroke-width="2"
/>
</svg>
<span
class="flex items-center text-[#4D5358]"
class="flex items-center text-button-md text-primary-gray hover:text-accent hover:underline"
>
Option 1
</span>
Expand Down