-
Notifications
You must be signed in to change notification settings - Fork 6
InsertTextComponent #491
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
InsertTextComponent #491
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
39572ba
InsertTextComponent
kavithakurella-dev 5ed44f0
resolved pr comments
kavithakurella-dev c8dfdda
InsertTextComponent
kavithakurella-dev ab3a89e
resolved pr comments
kavithakurella-dev 79957b2
resolved changes
kavithakurella-dev 4af1047
Resolved
kavithakurella-dev e5db50f
Resolved changes
kavithakurella-dev 219fb8f
feat: improve documentation
daniele-zurico 2c68781
feat: improve documentation
daniele-zurico 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import React from 'react'; | ||
| import { InsertText } from '@capgeminiuk/dcx-react-library'; | ||
|
|
||
| export const InsertTextDemo = () => { | ||
| return ( | ||
| <> | ||
| <div className="govuk-input"> | ||
| <h1>Demo of ComponentName</h1> | ||
| <InsertText value="insert text" /> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; |
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,39 @@ | ||
| import React from 'react'; | ||
| import { classNames } from '../common'; | ||
|
|
||
| export type InsertTextProps = { | ||
| /** | ||
| * specify a custom class name to be applied to the Insert-text | ||
| */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| *value specified by user | ||
| */ | ||
| value: 'insert text'; | ||
|
|
||
| /** | ||
| * It will pass an id to the InsertText element | ||
| */ | ||
| id?: string; | ||
|
|
||
| /** | ||
| * Additional props/attributes | ||
| */ | ||
| props?: React.HTMLAttributes<HTMLDivElement>; | ||
| }; | ||
KavithaKurella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const InsertText = ({ | ||
| value, | ||
| className, | ||
| id, | ||
| props, | ||
| }: InsertTextProps) => { | ||
| const classes = classNames(['dcx-insert-text', className]); | ||
|
|
||
| return ( | ||
| <div className={classes} id={id} {...props}> | ||
| {value} | ||
| </div> | ||
| ); | ||
| }; | ||
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,50 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { InsertText } from '../InsertText'; | ||
|
|
||
| describe('InsertText', () => { | ||
| it('should render', () => { | ||
KavithaKurella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| render(<InsertText value="insert text" id="user-defined-id" />); | ||
|
|
||
| expect(screen.getByText('insert text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should have the class dcx-insert-text if the user does not specify any additional class', () => { | ||
| render(<InsertText value="insert text" id="user-defined-id" />); | ||
| expect(screen.getByText('insert text')).toHaveClass('dcx-insert-text'); | ||
| }); | ||
|
|
||
| it('should have the class dcx-insert-text and the user based class if the user specifies any additional class', () => { | ||
| render( | ||
| <InsertText | ||
| value="insert text" | ||
| id="user-defined-id" | ||
| className="my-custom-class" | ||
| /> | ||
| ); | ||
| expect(screen.getByText('insert text')).toHaveClass('dcx-insert-text'); | ||
| expect(screen.getByText('insert text')).toHaveClass('my-custom-class'); | ||
| }); | ||
|
|
||
| it('should be able to pass some extra properties', () => { | ||
| const { container } = render( | ||
| <InsertText | ||
| value="insert text" | ||
| id="user-defined-id" | ||
| props={{ style: { color: 'red' } }} | ||
| /> | ||
| ); | ||
| const inserttextElement = | ||
| container.getElementsByClassName('dcx-insert-text'); | ||
| const style = window.getComputedStyle(inserttextElement[0]); | ||
| expect(style.color).toBe('red'); | ||
| }); | ||
|
|
||
| it('should be able to pass an id', () => { | ||
| const { container } = render( | ||
| <InsertText value="insert text" id="user_defined_id" /> | ||
| ); | ||
| expect(container.firstChild).toHaveAttribute('id', 'user_defined_id'); | ||
| }); | ||
| }); | ||
KavithaKurella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 { InsertText } from './InsertText'; |
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,20 @@ | ||
| import { InsertText } from '../../src/insertText/InsertText'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/InsertText/Class based', | ||
| component: InsertText, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| tags: ['autodocs'], | ||
| }; | ||
|
|
||
| export const Basic = { | ||
| name: 'Basic', | ||
| args: { | ||
| value: 'It can take up to 8 weeks to register a lasting power of attorney if there are no mistakes in the application.', | ||
| className: 'govuk-inset-text', | ||
KavithaKurella marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
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,34 @@ | ||
| import { | ||
| Meta, | ||
| Story, | ||
| Canvas, | ||
| Props, | ||
| ArgTypes, | ||
| } from '@storybook/addon-docs/blocks'; | ||
|
|
||
| import * as InsertTextStories from './UnStyled.stories'; | ||
|
|
||
| <Meta title="DCXLibrary/Typography/InsertText/Documentation" /> | ||
|
|
||
| # InsertText | ||
|
|
||
| An InsertText component ready to use in your application. | ||
| InsertText is UI/UX agnostic so you need to provide your style to have the look and feel you prefer. | ||
| When you import the InsertText component without providing any className or associated style it will looks as following: | ||
|
|
||
| <Canvas of={InsertTextStories.Unstyled} /> | ||
|
|
||
| A more complex example with all the possible properties is: | ||
|
|
||
| ```js | ||
| <InsertText | ||
| value="insert text" | ||
| id="user-defined-id" | ||
| className="my-class" | ||
| props={{ style: { color: red } }} | ||
| /> | ||
| ``` | ||
|
|
||
| Below a list of all the available properties: | ||
|
|
||
| <ArgTypes of={InsertTextStories} /> |
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,21 @@ | ||
| import { InsertText } from '../../src/insertText/InsertText'; | ||
| import InsertTextLive from '../liveEdit/InsertTextLive'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/InsertText/live', | ||
| component: InsertText, | ||
|
|
||
| parameters: { | ||
| options: { | ||
| showPanel: false, | ||
| }, | ||
| viewMode: 'docs', | ||
| previewTabs: { | ||
| canvas: { hidden: true }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Live = { | ||
| render: () => <InsertTextLive />, | ||
| }; |
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 { InsertText } from '../../src/insertText/InsertText'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/InsertText/Without style', | ||
| component: InsertText, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Unstyled = { | ||
| args: { | ||
| value: 'insert 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import React from 'react'; | ||
| import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live'; | ||
| import { InsertText } from '../../src/insertText/InsertText'; | ||
|
|
||
| const InsertTextDemo = ` | ||
| function InsertTextDemo() { | ||
|
|
||
| return ( | ||
| <InsertText value="insert text" id="user-defined-id" props={{}} className="" /> | ||
| ) | ||
| } | ||
| `.trim(); | ||
|
|
||
| const InsertTextLive = () => { | ||
| const scope = { InsertText }; | ||
| return ( | ||
| <LiveProvider code={InsertTextDemo} 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 InsertTextLive; |
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.