-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Create a reusable Label component #9833
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export type LabelVariant = 'default' | 'small'; | ||
|
||
const StyledLabel = styled.div<{ variant?: LabelVariant }>` | ||
color: ${({ theme }) => theme.font.color.light}; | ||
font-size: ${({ variant = 'default' }) => { | ||
switch (variant) { | ||
case 'default': | ||
return '11px'; | ||
case 'small': | ||
return '9px'; | ||
} | ||
}}; | ||
Comment on lines
+7
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Switch statement missing default case. Could cause undefined font-size if invalid variant is passed. |
||
font-weight: ${({ theme }) => theme.font.weight.semiBold}; | ||
`; | ||
|
||
export { StyledLabel as Label }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { CatalogDecorator } from '@ui/testing/decorators/CatalogDecorator'; | ||
import { ComponentDecorator } from '@ui/testing/decorators/ComponentDecorator'; | ||
import { CatalogStory } from '@ui/testing/types/CatalogStory'; | ||
|
||
import { Label, LabelVariant } from '../Label'; | ||
|
||
const meta: Meta<typeof Label> = { | ||
title: 'UI/Display/Typography/Label', | ||
component: Label, | ||
decorators: [ComponentDecorator], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Label>; | ||
|
||
export const Default: Story = { | ||
decorators: [ComponentDecorator], | ||
args: { | ||
children: 'Label', | ||
}, | ||
}; | ||
Comment on lines
+19
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: ComponentDecorator is redundant here since it's already defined in the meta object's decorators |
||
|
||
export const Catalog: CatalogStory<Story, typeof Label> = { | ||
decorators: [CatalogDecorator], | ||
args: { | ||
children: 'Label', | ||
}, | ||
parameters: { | ||
catalog: { | ||
dimensions: [ | ||
{ | ||
name: 'Variant', | ||
values: ['default', 'small'] satisfies LabelVariant[], | ||
props: (variant: LabelVariant) => ({ variant }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark: Unless I'm mistaken force cast is not mandatory here, might wanna use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this. My |
||
}, | ||
], | ||
}, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using semantic HTML by extending 'label' or 'span' instead of 'div' for better accessibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: isn't greptile right about this ? Or I've also misunderstood emotion styled here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label is not strictly meant to be used as part of a form. The benefit of exporting the component as-is is that it's possible to change the rendered element with the
as
prop.