-
Notifications
You must be signed in to change notification settings - Fork 6
KeyboardInput Component #504
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
83b6258
KeyboardInput Component
kavithakurella-dev 2170d8b
KeyboardInput
kavithakurella-dev 420c364
KeyboardInput
kavithakurella-dev 8525357
Commponent
kavithakurella-dev 6fa1735
KeyboardInput
kavithakurella-dev 6570085
feat: minor fix
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
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 { KeyboardInput } from '@capgeminiuk/dcx-react-library'; | ||
|
|
||
| export const KeyboardInputDemo = () => { | ||
| return ( | ||
| <> | ||
| <h1>Demo of KeyboardInput</h1> | ||
| <KeyboardInput>ctrl + p</KeyboardInput> | ||
| </> | ||
| ); | ||
| }; |
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,37 @@ | ||
| import React from 'react'; | ||
| import { classNames } from '../common'; | ||
|
|
||
| export type KeyboardInputProps = { | ||
| /** | ||
| * Specify a custom class name to be applied to the KeyboardInput | ||
| */ | ||
| className?: string; | ||
| /** | ||
| * Value specified by the user | ||
| */ | ||
| children: React.ReactNode; | ||
| /** | ||
| * It will pass an id to the KeyboardInput element | ||
| */ | ||
| id?: string; | ||
| /** | ||
| * Additional props/attributes | ||
| */ | ||
| props?: React.HTMLAttributes<HTMLElement>; | ||
| }; | ||
|
|
||
| export const KeyboardInput = ({ | ||
| children, | ||
| className, | ||
| id, | ||
| props, | ||
| }: KeyboardInputProps) => { | ||
| const classes = classNames(['dcx-keyboard-Input', className]); | ||
|
|
||
| // Return a kbd element with the dynamic class name and any additional props passed to the component | ||
| return ( | ||
| <kbd className={classes} id={id} {...props}> | ||
| {children} | ||
| </kbd> | ||
| ); | ||
| }; |
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,55 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import { KeyboardInput } from '../KeyboardInput'; | ||
|
|
||
| describe('KeyboardInput', () => { | ||
| it('should render', () => { | ||
| render( | ||
| <KeyboardInput | ||
| className="additional classes" | ||
| children="text" | ||
| id="user-defined-id" | ||
| /> | ||
| ); | ||
| expect(screen.getByText('text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should have the class dcx-keyboard-Input if the user does not specify any additional class', () => { | ||
| render(<KeyboardInput children="ctrl+p" id="user-defined-id" />); | ||
| expect(screen.getByText('ctrl+p')).toHaveClass('dcx-keyboard-Input'); | ||
| }); | ||
|
|
||
| it('should have the class dcx-keyboard-Input and the user based class if the user specifies any additional class', () => { | ||
| render( | ||
| <KeyboardInput | ||
| children="ctrl+p" | ||
| id="user-defined-id" | ||
| className="my-custom-class" | ||
| /> | ||
| ); | ||
| expect(screen.getByText('ctrl+p')).toHaveClass('dcx-keyboard-Input'); | ||
| expect(screen.getByText('ctrl+p')).toHaveClass('my-custom-class'); | ||
| }); | ||
|
|
||
| it('should be able to pass some extra properties', () => { | ||
| const { container } = render( | ||
| <KeyboardInput | ||
| children="ctrl+p" | ||
| id="user-defined-id" | ||
| props={{ style: { color: 'red' } }} | ||
| /> | ||
| ); | ||
| const keyboadInputElement = | ||
| container.getElementsByClassName('dcx-keyboard-Input'); | ||
| const style = window.getComputedStyle(keyboadInputElement[0]); | ||
| expect(style.color).toBe('red'); | ||
| }); | ||
|
|
||
| it('should be able to pass an id', () => { | ||
| const { container } = render( | ||
| <KeyboardInput children="ctrl+p" id="user_defined_id" /> | ||
| ); | ||
| expect(container.firstChild).toHaveAttribute('id', 'user_defined_id'); | ||
| }); | ||
| }); | ||
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 { KeyboardInput } from './KeyboardInput'; |
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,23 @@ | ||
| import { KeyboardInput } from '../../src/keyBoard/KeyboardInput'; | ||
| /** | ||
| * In this section we're using the KeyboardInput component passing the relative className. | ||
| * Feel free to use your own css to style the KeyboardInput as you prefer. | ||
| */ | ||
| export default { | ||
| title: 'DCXLibrary/Typography/KeyboardInput/Class based', | ||
| component: KeyboardInput, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| tags: ['autodocs'], | ||
| }; | ||
|
|
||
| export const Basic = { | ||
| name: 'Basic', | ||
| args: { | ||
| children: 'ctrl+p', | ||
| className: 'kbd', | ||
| }, | ||
| }; |
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 KeyboardInputStories from './UnStyled.stories'; | ||
|
|
||
| <Meta title="DCXLibrary/Typography/KeyboardInput/Documentation" /> | ||
|
|
||
| # KeyboardInput | ||
|
|
||
| KeyboardInput component ready to use in your application. | ||
| KeyboardInput is UI/UX agnostic so you need to provide your style to have the look and feel you prefer. | ||
| When you import the KeyboardInput component without providing any className or associated style it will looks as following: | ||
|
|
||
| <Canvas of={KeyboardInputStories.Unstyled} /> | ||
|
|
||
| A more complex example with all the possible properties is: | ||
|
|
||
| ```js | ||
| <KeyboardInput | ||
| className="additional classes" | ||
| children="ctrl+p" | ||
| id="user-defined-id" | ||
| props={{ style: { color: red } }} | ||
| /> | ||
| ``` | ||
|
|
||
| Below a list of all the available properties: | ||
|
|
||
| <ArgTypes of={KeyboardInputStories} /> |
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 { KeyboardInput } from '../../src/label/Label'; | ||
| import KeyboardInputLive from '../liveEdit/KeyboardInputLive'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/KeyboardInput/Live', | ||
| component: KeyboardInput, | ||
|
|
||
| parameters: { | ||
| options: { | ||
| showPanel: false, | ||
| }, | ||
| viewMode: 'docs', | ||
| previewTabs: { | ||
| canvas: { | ||
| hidden: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Live = { | ||
| render: () => <KeyboardInputLive />, | ||
| }; |
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 { KeyboardInput } from '../../src/keyBoard/KeyboardInput'; | ||
|
|
||
| export default { | ||
| title: 'DCXLibrary/Typography/KeyboardInput/Without style', | ||
| component: KeyboardInput, | ||
| parameters: { | ||
| options: { | ||
| showPanel: true, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const Unstyled = { | ||
| args: { | ||
| children: 'ctrl+p', | ||
| }, | ||
| }; |
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 { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live'; | ||
| import { KeyboardInput } from '../../src/keyBoard/KeyboardInput'; | ||
|
|
||
| const KeyboardInputDemo = ` | ||
| function KeyboardInputDemo() { | ||
|
|
||
| return ( | ||
| <KeyboardInput id="user-defined-id" props={{}} className="">ctrl + p</KeyboardInput> | ||
| ) | ||
| } | ||
| `.trim(); | ||
|
|
||
| const KeyboardInputLive = () => { | ||
| const scope = { KeyboardInput }; | ||
| return ( | ||
| <LiveProvider code={KeyboardInputDemo} 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 KeyboardInputLive; |
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.