-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app): update software keyboard components to align with the lates…
…t design First change component name close AUTH-133
- Loading branch information
Showing
8 changed files
with
199 additions
and
102 deletions.
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
98 changes: 98 additions & 0 deletions
98
app/src/atoms/SoftwareKeyboard/NumericalKeyboard/__tests__/NumericalKeyboard.test.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,98 @@ | ||
import * as React from 'react' | ||
import { describe, it, expect, vi } from 'vitest' | ||
import '@testing-library/jest-dom/vitest' | ||
import { fireEvent, renderHook, screen } from '@testing-library/react' | ||
import { renderWithProviders } from '../../../../__testing-utils__' | ||
import { NumericalKeyboard } from '..' | ||
|
||
const render = (props: React.ComponentProps<typeof NumericalKeyboard>) => { | ||
return renderWithProviders(<NumericalKeyboard {...props} />)[0] | ||
} | ||
|
||
describe('NumericalKeyboard', () => { | ||
it('should render the numpad keys decimal off', () => { | ||
const { result } = renderHook(() => React.useRef(null)) | ||
const props = { | ||
onChange: vi.fn(), | ||
keyboardRef: result.current, | ||
isDecimal: false, | ||
} | ||
render(props) | ||
const buttons = screen.getAllByRole('button') | ||
const expectedButtonNames = [ | ||
'1', | ||
'2', | ||
'3', | ||
'4', | ||
'5', | ||
'6', | ||
'7', | ||
'8', | ||
'9', | ||
'', | ||
'0', | ||
'del', | ||
] | ||
|
||
buttons.forEach((button, index) => { | ||
const expectedName = expectedButtonNames[index] | ||
expect(button).toHaveTextContent(expectedName) | ||
}) | ||
}) | ||
|
||
it('should render the numpad keys decimal on', () => { | ||
const { result } = renderHook(() => React.useRef(null)) | ||
const props = { | ||
onChange: vi.fn(), | ||
keyboardRef: result.current, | ||
isDecimal: true, | ||
} | ||
render(props) | ||
const buttons = screen.getAllByRole('button') | ||
const expectedButtonNames = [ | ||
'1', | ||
'2', | ||
'3', | ||
'4', | ||
'5', | ||
'6', | ||
'7', | ||
'8', | ||
'9', | ||
'.', | ||
'0', | ||
'del', | ||
] | ||
|
||
buttons.forEach((button, index) => { | ||
const expectedName = expectedButtonNames[index] | ||
expect(button).toHaveTextContent(expectedName) | ||
}) | ||
}) | ||
|
||
it('should call mock function when clicking num key', () => { | ||
const { result } = renderHook(() => React.useRef(null)) | ||
const props = { | ||
onChange: vi.fn(), | ||
keyboardRef: result.current, | ||
isDecimal: false, | ||
} | ||
render(props) | ||
const numKey = screen.getByRole('button', { name: '1' }) | ||
fireEvent.click(numKey) | ||
expect(props.onChange).toHaveBeenCalled() | ||
}) | ||
|
||
it('should call mock function when clicking decimal point key', () => { | ||
const { result } = renderHook(() => React.useRef(null)) | ||
const props = { | ||
onChange: vi.fn(), | ||
keyboardRef: result.current, | ||
isDecimal: true, | ||
} | ||
render(props) | ||
const numKey = screen.getByRole('button', { name: '.' }) | ||
fireEvent.click(numKey) | ||
expect(props.onChange).toHaveBeenCalled() | ||
}) | ||
}) |
27 changes: 27 additions & 0 deletions
27
app/src/atoms/SoftwareKeyboard/NumericalKeyboard/index.css
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,27 @@ | ||
/* stylelint-disable */ | ||
|
||
.numerical-keyboard button.hg-button.hg-button-backspace, | ||
.numerical-keyboard button.hg-button.hg-button-abc, | ||
.numerical-keyboard button.hg-button.hg-standardBtn { | ||
flex: 1; | ||
} | ||
|
||
.numerical-keyboard button.hg-button.hg-button-backspace span, | ||
.numerical-keyboard button.hg-button.hg-button-abc span, | ||
.numerical-keyboard button.hg-button.hg-standardBtn span { | ||
text-align: center; | ||
font-size: 20px; | ||
font-weight: 600; | ||
line-height: 24px; | ||
} | ||
|
||
div:nth-child(4) .hg-button.hg-standardBtn:nth-child(1) { | ||
background-color: transparent; | ||
box-shadow: none; | ||
cursor: none; | ||
} | ||
|
||
.numerical-keyboard button.hg-button.hg-standardBtn.hg-decimal-point { | ||
background-color: #fff; | ||
cursor: pointer; | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/atoms/SoftwareKeyboard/NumericalKeyboard/index.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,48 @@ | ||
import * as React from 'react' | ||
import Keyboard from 'react-simple-keyboard' | ||
|
||
const customDisplay = { | ||
'{backspace}': 'del', | ||
} | ||
interface NumericalKeyboardProps { | ||
onChange: (input: string) => void | ||
keyboardRef: React.MutableRefObject<null> | ||
isDecimal?: boolean | ||
} | ||
|
||
const decimalOffKeyboard = ['1 2 3', '4 5 6', '7 8 9', ' 0 {backspace}'] | ||
const decimalOnKeyboard = ['1 2 3', '4 5 6', '7 8 9', '. 0 {backspace}'] | ||
|
||
export function NumericalKeyboard({ | ||
onChange, | ||
keyboardRef, | ||
isDecimal = false, | ||
}: NumericalKeyboardProps): JSX.Element { | ||
const numericalKeyboard = { | ||
layout: { | ||
default: isDecimal ? decimalOnKeyboard : decimalOffKeyboard, | ||
}, | ||
} | ||
return ( | ||
/* | ||
* autoUseTouchEvents: for Flex on-device app | ||
* useButtonTag: this is for testing purpose that each key renders as a button | ||
*/ | ||
<Keyboard | ||
keyboardRef={r => (keyboardRef.current = r)} | ||
theme={'hg-theme-default oddTheme1 numerical-keyboard'} | ||
onChange={onChange} | ||
layoutName="default" | ||
buttonTheme={[ | ||
{ | ||
class: 'hg-decimal-point', | ||
buttons: '.', | ||
}, | ||
]} | ||
display={customDisplay} | ||
autoUseTouchEvents={true} | ||
useButtonTag={true} | ||
{...numericalKeyboard} | ||
/> | ||
) | ||
} |
53 changes: 0 additions & 53 deletions
53
app/src/atoms/SoftwareKeyboard/Numpad/__tests__/Numpad.test.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 +1,3 @@ | ||
export { CustomKeyboard } from './CustomKeyboard' | ||
export { NormalKeyboard } from './NormalKeyboard' | ||
export { Numpad } from './Numpad' | ||
export { Numpad } from './NumericalKeyboard' | ||