-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(composer):Scene Hierarchy radio buttons & bug fix for selection o…
…n single click (#326) * fix(composer): Implementing Scene Hierarchy radio buttons for single-click select & bug fix for selection on single click * Implementing PR feedback Co-authored-by: Emily Dodds <dodemily@amazon.com>
- Loading branch information
Showing
23 changed files
with
811 additions
and
314 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
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
File renamed without changes.
74 changes: 74 additions & 0 deletions
74
packages/scene-composer/src/components/RadioButton/__tests__/RadioButton.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,74 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import RadioButton from '../index'; | ||
|
||
describe('RadioButton', () => { | ||
[ | ||
[ | ||
'First Option', | ||
{ | ||
testId: 'one', | ||
selected: false, | ||
toggle: () => { | ||
return null; | ||
}, | ||
label: 'radio one', | ||
}, | ||
], | ||
[ | ||
'Second Option', | ||
{ | ||
testId: 'two', | ||
selected: true, | ||
toggle: () => { | ||
return null; | ||
}, | ||
label: 'radio two', | ||
}, | ||
], | ||
[ | ||
'Third Option', | ||
{ | ||
testId: 'three', | ||
selected: false, | ||
toggle: () => { | ||
return null; | ||
}, | ||
label: 'radio three', | ||
}, | ||
], | ||
[ | ||
'Fourth Option', | ||
{ | ||
testId: 'four', | ||
selected: false, | ||
toggle: () => { | ||
return null; | ||
}, | ||
label: 'radio four', | ||
}, | ||
], | ||
[ | ||
'Fifth Option', | ||
{ | ||
testId: 'five', | ||
selected: false, | ||
toggle: () => { | ||
return null; | ||
}, | ||
label: 'radio five', | ||
}, | ||
], | ||
].forEach((item) => { | ||
it(`it should render the ${item[0]} as a radio button`, () => { | ||
const data = item[1] as any; | ||
const { selected, testId, toggle, label } = data; | ||
|
||
const { getByTestId } = render(<RadioButton selected={selected} testId={testId} toggle={toggle} label={label} />); | ||
const radioBtn: any = getByTestId(testId); | ||
|
||
expect(radioBtn).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...ene-composer/src/components/RadioButton/__tests__/__snapshots__/RadioButton.spec.tsx.snap
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,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`RadioButton it should render the Fifth Option as a radio button 1`] = ` | ||
<input | ||
data-testid="five" | ||
type="radio" | ||
value="radio five" | ||
/> | ||
`; | ||
|
||
exports[`RadioButton it should render the First Option as a radio button 1`] = ` | ||
<input | ||
data-testid="one" | ||
type="radio" | ||
value="radio one" | ||
/> | ||
`; | ||
|
||
exports[`RadioButton it should render the Fourth Option as a radio button 1`] = ` | ||
<input | ||
data-testid="four" | ||
type="radio" | ||
value="radio four" | ||
/> | ||
`; | ||
|
||
exports[`RadioButton it should render the Second Option as a radio button 1`] = ` | ||
<input | ||
checked="" | ||
data-testid="two" | ||
type="radio" | ||
value="radio two" | ||
/> | ||
`; | ||
|
||
exports[`RadioButton it should render the Third Option as a radio button 1`] = ` | ||
<input | ||
data-testid="three" | ||
type="radio" | ||
value="radio three" | ||
/> | ||
`; |
19 changes: 19 additions & 0 deletions
19
packages/scene-composer/src/components/RadioButton/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,19 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import './radio-button.scss'; | ||
|
||
export interface RadioButtonProps { | ||
checked?: boolean; | ||
label?: string; | ||
selected?: boolean; | ||
testId?: string; | ||
toggle: (e: any) => void; | ||
} | ||
|
||
const RadioButton: FC<RadioButtonProps> = ({ label, selected, testId, toggle }) => { | ||
return <input checked={selected} data-testid={testId} onChange={toggle} type='radio' value={label} />; | ||
}; | ||
|
||
RadioButton.displayName = 'RadioButton'; | ||
|
||
export default RadioButton; |
13 changes: 13 additions & 0 deletions
13
packages/scene-composer/src/components/RadioButton/radio-button.scss
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,13 @@ | ||
input[type="radio"] { | ||
margin-right: 1rem; | ||
|
||
// styled to match Polaris: https://polaris.a2z.com/components/radio-group/ | ||
&:checked { | ||
appearance: none; | ||
background-color: #fff; | ||
color: #fff; | ||
border: 4px solid #00a1c9; | ||
border-radius: 50%; | ||
padding: 3px; | ||
} | ||
} |
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
Oops, something went wrong.