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

Labelコンポーネントの修正 #338

Merged
merged 4 commits into from
Dec 13, 2023
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
19 changes: 13 additions & 6 deletions src/components/base/Label/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ type Story = StoryObj<typeof BaseLabel>;
export const Label: Story = {
render: () => (
<dl>
<dt style={{ marginBottom: '8px' }}>Default</dt>
<dd style={{ marginBottom: '24px' }}>
<BaseLabel>Required label</BaseLabel>
<dt style={{ color: 'white', marginBottom: '8px' }}>Default</dt>
<dd style={{ color: 'white', marginBottom: '24px' }}>
<BaseLabel text="Required label" />
</dd>
<dt style={{ marginBottom: '8px' }}>Not required</dt>
<dd style={{ marginBottom: '24px' }}>
<BaseLabel isRequired={false}>Not required label</BaseLabel>
<dt style={{ color: 'white', marginBottom: '8px' }}>Not required</dt>
<dd style={{ color: 'white', marginBottom: '24px' }}>
<BaseLabel isRequired={false} text="Not required label" />
</dd>
<dt style={{ color: 'white', marginBottom: '8px' }}>Form</dt>
<dd style={{ color: 'white', marginBottom: '24px' }}>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<BaseLabel htmlFor="textbox" text="textbox" />
<input aria-required id="textbox" type="text" />
</div>
</dd>
</dl>
),
Expand Down
15 changes: 12 additions & 3 deletions src/components/base/Label/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { styles } from './styles.css';
import type { ComponentPropsWithoutRef, FC } from 'react';

type BaseProps = {
/**
* ラベルのテキスト
*/
text: string;
/**
* 必須かどうか
*/
Expand All @@ -13,10 +17,15 @@ type BaseProps = {

type Props = BaseProps & Omit<ComponentPropsWithoutRef<'label'>, keyof BaseProps>;

const Label: FC<Props> = ({ isRequired = true, htmlFor, children }) => {
const Label: FC<Props> = ({ text, isRequired = true, className, ...props }) => {
return (
<label className={clsx(styles.label, isRequired && styles.requiredMark)} htmlFor={htmlFor}>
{children}
<label className={clsx(styles.label, className)} {...props}>
{text}
{isRequired && (
<span aria-hidden className={styles.requiredMark}>
*
</span>
)}
</label>
);
};
Expand Down
27 changes: 10 additions & 17 deletions src/components/base/Label/styles.css.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { style } from '@vanilla-extract/css';

import { sprinkles } from '@/styles/sprinkles.css';
import { vars } from '@/styles/themes.css';

const styles = {
label: sprinkles({
fontSize: {
mobile: 14,
desktop: 16,
},
color: 'black',
display: 'inline-flex',
fontSize: 16,
color: 'white',
lineHeight: 1,
}),
requiredMark: style({
position: 'relative',
'::after': {
content: '*',
position: 'absolute',
top: '-75%',
color: vars.colors.red,
paddingLeft: vars.spacing['0.5'],
},
requiredMark: sprinkles({
display: 'inline-block',
fontSize: 14,
fontWeight: 'bold',
color: 'red',
paddingLeft: 0.5,
}),
};

Expand Down
2 changes: 1 addition & 1 deletion src/styles/themes.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const colors = {
lightBlue: '#0080FF',
hoverBlue: 'rgba(30, 26, 222, 0.8)',
purple: '#B01CF6',
red: '#E6002F',
red: '#FF4747',
lightRed: '#FBD4D4',
} as const;

Expand Down