-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature/pxweb2 90 label #38
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dfe3e22
Added Label component
MikaelNordberg 87433e0
Added property visuallyHidden
MikaelNordberg 4b47506
Label extends HTMLLabelElement and HTMLLegendElement instead of HTMLP…
MikaelNordberg 5511039
Merge branch 'main' into feature/PXWEB2-90-Label
KentMossback File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './lib/components/Typography/Label/Label'; | ||
export * from './lib/components/Button/Button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@use '../../../../../style-dictionary/dist/scss/fixed-variables.scss' as fixed; | ||
|
||
.label { | ||
font-family: PxWeb-font-500; | ||
font-weight: 500; | ||
letter-spacing: 0em; | ||
margin: 0; | ||
} | ||
|
||
.small { | ||
font-size: 14px; | ||
line-height: 20px; | ||
} | ||
|
||
.medium { | ||
font-size: 16px; | ||
line-height: 24px; | ||
} | ||
|
||
.align-start{ | ||
text-align: start; | ||
} | ||
|
||
.align-center{ | ||
text-align: center; | ||
} | ||
|
||
.align-end{ | ||
text-align: end; | ||
} | ||
|
||
.textcolor-default{ | ||
color: var(--px-color-text-default); | ||
} | ||
|
||
.textcolor-subtle{ | ||
color: var(--px-color-text-subtle); | ||
} | ||
|
||
.visually-hidden { | ||
border: 0 !important; | ||
clip: rect(0, 0, 0, 0) !important; | ||
height: 1px !important; | ||
margin: -1px !important; | ||
overflow: hidden !important; | ||
padding: 0 !important; | ||
top: 0 !important; | ||
position: absolute !important; | ||
white-space: nowrap !important; | ||
width: 1px !important; | ||
} |
10 changes: 10 additions & 0 deletions
10
libs/pxweb2-ui/src/lib/components/Typography/Label/Label.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import Label from './Label'; | ||
|
||
describe('Label', () => { | ||
it('should render successfully', () => { | ||
const { baseElement } = render(<Label />); | ||
expect(baseElement).toBeTruthy(); | ||
}); | ||
}); |
90 changes: 90 additions & 0 deletions
90
libs/pxweb2-ui/src/lib/components/Typography/Label/Label.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import type { Meta, StoryFn } from '@storybook/react'; | ||
import { Label } from './Label'; | ||
|
||
const meta: Meta<typeof Label> = { | ||
component: Label, | ||
title: 'Label', | ||
}; | ||
export default meta; | ||
|
||
const text = 'This is a label'; | ||
|
||
export const Default = { | ||
args: { | ||
children: text | ||
}, | ||
argTypes: { | ||
size: { | ||
options: ['medium', 'small'], | ||
control: { type: 'radio' } | ||
} | ||
} | ||
}; | ||
|
||
export const Size: StoryFn<typeof Label> = () => { | ||
return ( | ||
<> | ||
<h1>Size</h1> | ||
|
||
<h2>default:</h2> | ||
<Label>{text}</Label> | ||
|
||
<h2>medium:</h2> | ||
<Label size='medium'>{text}</Label> | ||
|
||
<h2>small:</h2> | ||
<Label size='small'>{text}</Label> | ||
</> | ||
); | ||
}; | ||
|
||
export const Align: StoryFn<typeof Label> = () => { | ||
return ( | ||
<> | ||
<h1>Align</h1> | ||
|
||
<h2>Default:</h2> | ||
<Label>{text}</Label> | ||
|
||
<h2>start:</h2> | ||
<Label align='start'>{text}</Label> | ||
|
||
<h2>center:</h2> | ||
<Label align='center'>{text}</Label> | ||
|
||
<h2>end:</h2> | ||
<Label align='end'>{text}</Label> | ||
</> | ||
); | ||
}; | ||
|
||
export const Textcolor: StoryFn<typeof Label> = () => { | ||
return ( | ||
<> | ||
<h1>Textcolor</h1> | ||
|
||
<h2>Default:</h2> | ||
<Label>{text}</Label> | ||
|
||
<h2>default:</h2> | ||
<Label textcolor='default'>{text}</Label> | ||
|
||
<h2>subtle:</h2> | ||
<Label textcolor='subtle'>{text}</Label> | ||
</> | ||
); | ||
}; | ||
|
||
export const VisuallyHidden: StoryFn<typeof Label> = () => { | ||
return ( | ||
<> | ||
<h1>VisuallyHidden</h1> | ||
|
||
<h2>Default:</h2> | ||
<Label>{text}</Label> | ||
|
||
<h2>hidden:</h2> | ||
<Label visuallyHidden>{text}</Label> | ||
</> | ||
); | ||
}; |
36 changes: 36 additions & 0 deletions
36
libs/pxweb2-ui/src/lib/components/Typography/Label/Label.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import cl from 'clsx'; | ||
import classes from './Label.module.scss'; | ||
|
||
export interface LabelProps extends React.HTMLAttributes<HTMLParagraphElement> { | ||
size?: 'medium' | 'small'; | ||
align?: 'start' | 'center' | 'end'; | ||
textcolor?: 'default' | 'subtle'; | ||
visuallyHidden?: boolean; | ||
children?: React.ReactNode; | ||
} | ||
|
||
export function Label({ | ||
size = 'medium', | ||
align = 'start', | ||
textcolor = 'default', | ||
visuallyHidden = false, | ||
children, | ||
...rest | ||
}: LabelProps) { | ||
return ( | ||
<p | ||
className={cl( | ||
classes.label, | ||
classes[size], | ||
cl({[classes[`align-${align}`]]: align}), | ||
cl({[classes[`textcolor-${textcolor}`]]: textcolor}), | ||
cl({[classes['visually-hidden']]: visuallyHidden}) | ||
)} | ||
{...rest} | ||
> | ||
{children} | ||
</p> | ||
); | ||
} | ||
|
||
export default Label; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should probably be a span. A
<p>
tag is for paragraphsThere 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.
@michaelpande
Now is a label element with the possibility to set htmlFor: