-
Notifications
You must be signed in to change notification settings - Fork 6
Feature/label #483
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
Merged
Merged
Feature/label #483
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fd69486
Button demo test
JadhavJeet 6554873
Created Label component
JadhavJeet 7307000
added return statement
JadhavJeet e3b03c5
dcx-label embeded class updated
JadhavJeet 70e9cb1
removed return statement
JadhavJeet 2b1312e
Merge branch 'release/0.8' of https://github.com/Capgemini/dcx-react-…
JadhavJeet 5b1d4ea
resolved all issues and added classbased stories
JadhavJeet bf9fd5b
dcx-label, value mandatory field, govuk-label
JadhavJeet b9f9fe9
added Typography for stories
JadhavJeet 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 hidden or 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 hidden or 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,11 @@ | ||
| import React from 'react'; | ||
| import { Label } from '@capgeminiuk/dcx-react-library'; | ||
|
|
||
| export const LabelDemo = () => { | ||
| return ( | ||
| <> | ||
| <h1>Demo of Label</h1> | ||
| <Label value="text" /> | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| import React from 'react'; | ||
| import { classNames } from '../common'; | ||
|
|
||
| type labelProps = { | ||
| /** | ||
| * A CSS class for styling label | ||
| */ | ||
| className?: string; | ||
| /** | ||
| * define the value of the label | ||
| */ | ||
| value: string; | ||
| /** | ||
| * it will pass an id to the label element | ||
| */ | ||
| id?: string; | ||
| /** | ||
| * Additional props/attributes | ||
| */ | ||
| props?: React.HtmlHTMLAttributes<HTMLLabelElement>; | ||
| }; | ||
|
|
||
| export const Label = ({ className, value, id, props }: labelProps) => ( | ||
| <label className={classNames(['dcx-label', className])} id={id} {...props}> | ||
| {value} | ||
| </label> | ||
| ); | ||
This file contains hidden or 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,39 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| import { Label } from '../Label'; | ||
|
|
||
| describe('Label', () => { | ||
| it('should render', () => { | ||
daniele-zurico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| render( | ||
| <Label className="additional classes" value="text" id="user-defined-id" /> | ||
| ); | ||
| expect(screen.getByText('text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render with the dcx-label className when no className Provided', () => { | ||
| const { container } = render(<Label value="text" />); | ||
| expect(container.querySelector('.dcx-label')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should be able to render the dcx-label and the user specific className', () => { | ||
| const { container } = render(<Label value="text" className="styleOne" />); | ||
| expect(container.querySelector('.dcx-label')).toBeInTheDocument(); | ||
| expect(container.querySelector('.styleOne')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should be able to pass an id', () => { | ||
| const { container } = render(<Label value="text" id="my_id" />); | ||
| expect(container.firstChild).toHaveAttribute('id', 'my_id'); | ||
| }); | ||
|
|
||
| it('should be able to pass some extra properties', () => { | ||
| const { container } = render( | ||
| <Label value="text" props={{ style: { color: 'red' } }} /> | ||
| ); | ||
| const labelElement = container.getElementsByClassName('dcx-label'); | ||
| const style = window.getComputedStyle(labelElement[0]); | ||
| expect(style.color).toBe('red'); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 @@ | ||
| export { Label } from './Label'; |
This file contains hidden or 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,24 @@ | ||
| import { Label } from '../../src/label/Label'; | ||
|
|
||
| /** | ||
| * In this section we're using the Label component providing the **GovUk style** passing the relative className. | ||
| * Feel free to use your own css to style the formInput as you prefer. | ||
| */ | ||
| export default { | ||
| title: 'DCXLibrary/Typography/Label/Class based', | ||
| component: Label, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| tags: ['autodocs'], | ||
| }; | ||
|
|
||
| export const Basic = { | ||
| name: 'Basic', | ||
| args: { | ||
| value: 'text', | ||
| className: 'govuk-label', | ||
| }, | ||
| }; |
This file contains hidden or 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,27 @@ | ||
| import { Meta, Canvas, ArgTypes } from '@storybook/blocks'; | ||
| import * as LabelStories from './UnStyled.stories'; | ||
|
|
||
| <Meta title="DCXLibrary/Typography/Label/Documentation" /> | ||
|
|
||
| # Label | ||
|
|
||
| A Label component ready to use in your form. | ||
| Label is UI/UX agnostic so you need to provide your style to have the look and feel you prefer. | ||
| When you import the label component without providing any className or style associated will looks as following: | ||
|
|
||
| <Canvas of={LabelStories.Unstyled} /> | ||
|
|
||
| A more complex example with all the possible properties is: | ||
|
|
||
| ```js | ||
| <Label | ||
| className="additional classes" | ||
| value="text" | ||
| id="user-defined-id" | ||
daniele-zurico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| props={{ style: { color: red } }} | ||
| /> | ||
| ``` | ||
|
|
||
| Below a list of all the available properties: | ||
|
|
||
| <ArgTypes of={LabelStories} /> | ||
This file contains hidden or 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,23 @@ | ||
| import { Label } from '../../src/label/Label'; | ||
| import LabelLive from '../liveEdit/LabelLive'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/Label/Live', | ||
| component: Label, | ||
|
|
||
| parameters: { | ||
| options: { | ||
| showPanel: false, | ||
| }, | ||
| viewMode: 'docs', | ||
| previewTabs: { | ||
| canvas: { | ||
| hidden: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Live = { | ||
| render: () => <LabelLive />, | ||
| }; |
This file contains hidden or 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,17 @@ | ||
| import { Label } from '../../src/label/Label'; | ||
daniele-zurico marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/Label/Without style', | ||
| component: Label, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Unstyled = { | ||
| args: { | ||
| value: 'text', | ||
| }, | ||
| }; | ||
This file contains hidden or 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,29 @@ | ||
| import React from 'react'; | ||
| import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live'; | ||
| import { Label } from '../../src/label/Label'; | ||
|
|
||
| const LabelDemo = ` | ||
| function LabelDemo() { | ||
|
|
||
| return ( | ||
| <Label | ||
| className="additional classes" value="text" id="user-defined-id" props={{}} | ||
| /> | ||
| ) | ||
| } | ||
| `.trim(); | ||
|
|
||
| const LabelLive = () => { | ||
| const scope = { Label }; | ||
| return ( | ||
| <LiveProvider code={LabelDemo} scope={scope}> | ||
| <div className="container"> | ||
| <LiveEditor className="liveEditor" aria-label="editor" /> | ||
| <LivePreview className="livePreview" aria-label="preview" /> | ||
| </div> | ||
| <LiveError className="liveError" aria-label="error" /> | ||
| </LiveProvider> | ||
| ); | ||
| }; | ||
|
|
||
| export default LabelLive; |
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.
Uh oh!
There was an error while loading. Please reload this page.