-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create Checkbox * Remove touchable
- Loading branch information
Showing
16 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/component-library/components/Checkbox/Checkbox.stories.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,14 @@ | ||
/* eslint-disable no-console */ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react-native'; | ||
import Checkbox from './Checkbox'; | ||
import { boolean } from '@storybook/addon-knobs'; | ||
|
||
storiesOf('Component Library / Checkbox', module) | ||
.addDecorator((getStory) => getStory()) | ||
.add('Default', () => { | ||
const groupId = 'Props'; | ||
const selectedSelector = boolean('isSelected', false, groupId); | ||
|
||
return <Checkbox isSelected={selectedSelector} />; | ||
}); |
22 changes: 22 additions & 0 deletions
22
app/component-library/components/Checkbox/Checkbox.styles.ts
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,22 @@ | ||
import { StyleSheet, ViewStyle } from 'react-native'; | ||
import { CheckboxStyleSheet, CheckboxStyleSheetVars } from './Checkbox.types'; | ||
|
||
/** | ||
* Style sheet function for Checkbox component. | ||
* | ||
* @param params Style sheet params. | ||
* @param params.theme App theme from ThemeContext. | ||
* @param params.vars Inputs that the style sheet depends on. | ||
* @returns StyleSheet object. | ||
*/ | ||
const styleSheet = (params: { | ||
vars: CheckboxStyleSheetVars; | ||
}): CheckboxStyleSheet => { | ||
const { vars } = params; | ||
const { style } = vars; | ||
return StyleSheet.create({ | ||
base: Object.assign({} as ViewStyle, style) as ViewStyle, | ||
}); | ||
}; | ||
|
||
export default styleSheet; |
30 changes: 30 additions & 0 deletions
30
app/component-library/components/Checkbox/Checkbox.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,30 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Checkbox from './Checkbox'; | ||
import { CHECKBOX_ICON_ID } from '../../../constants/test-ids'; | ||
import { IconName } from '../Icon'; | ||
|
||
describe('Checkbox', () => { | ||
it('should render correctly', () => { | ||
const wrapper = shallow(<Checkbox isSelected />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render correct icon when selected', () => { | ||
const wrapper = shallow(<Checkbox isSelected />); | ||
const iconComponent = wrapper.findWhere( | ||
(node) => node.prop('testID') === CHECKBOX_ICON_ID, | ||
); | ||
const iconName = iconComponent.props().name; | ||
expect(iconName).toBe(IconName.CheckBoxOnFilled); | ||
}); | ||
|
||
it('should render correct icon when not selected', () => { | ||
const wrapper = shallow(<Checkbox isSelected={false} />); | ||
const iconComponent = wrapper.findWhere( | ||
(node) => node.prop('testID') === CHECKBOX_ICON_ID, | ||
); | ||
const iconName = iconComponent.props().name; | ||
expect(iconName).toBe(IconName.CheckBoxOffOutline); | ||
}); | ||
}); |
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,36 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React, { useMemo } from 'react'; | ||
import { useStyles } from '../../hooks'; | ||
import Icon, { IconName, IconSize } from '../Icon'; | ||
import styleSheet from './Checkbox.styles'; | ||
import { CheckboxProps } from './Checkbox.types'; | ||
import { CHECKBOX_ICON_ID } from '../../../constants/test-ids'; | ||
|
||
const Checkbox = ({ style, isSelected, ...props }: CheckboxProps) => { | ||
const { | ||
styles, | ||
theme: { colors }, | ||
} = useStyles(styleSheet, { style, isSelected }); | ||
const iconName = useMemo( | ||
() => | ||
isSelected ? IconName.CheckBoxOnFilled : IconName.CheckBoxOffOutline, | ||
[isSelected], | ||
); | ||
const iconColor = useMemo( | ||
() => (isSelected ? colors.primary.default : colors.icon.muted), | ||
[isSelected, colors], | ||
); | ||
|
||
return ( | ||
<Icon | ||
testID={CHECKBOX_ICON_ID} | ||
name={iconName} | ||
size={IconSize.Lg} | ||
color={iconColor} | ||
style={styles.base} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default Checkbox; |
30 changes: 30 additions & 0 deletions
30
app/component-library/components/Checkbox/Checkbox.types.ts
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,30 @@ | ||
import { StyleProp, ViewProps, ViewStyle } from 'react-native'; | ||
|
||
/** | ||
* Checkbox component props. | ||
*/ | ||
export interface CheckboxProps extends ViewProps { | ||
/** | ||
* Determines if checkbox is selected. | ||
*/ | ||
isSelected: boolean; | ||
/** | ||
* Escape hatch for applying extra styles. Only use if absolutely necessary. | ||
*/ | ||
style?: StyleProp<ViewStyle>; | ||
} | ||
|
||
/** | ||
* Checkbox component style sheet. | ||
*/ | ||
export interface CheckboxStyleSheet { | ||
base: ViewStyle; | ||
} | ||
|
||
/** | ||
* Style sheet input parameters. | ||
*/ | ||
export type CheckboxStyleSheetVars = Pick< | ||
CheckboxProps, | ||
'style' | 'isSelected' | ||
>; |
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,15 @@ | ||
# Checkbox | ||
|
||
Checkbox is a component typically used for multi-select scenarios. | ||
|
||
## Props | ||
|
||
This component extends `ViewProps` from React Native's [View Component](https://reactnative.dev/docs/view). | ||
|
||
### `isSelected` | ||
|
||
Determines if checkbox is selected. | ||
|
||
| <span style="color:gray;font-size:14px">TYPE</span> | <span style="color:gray;font-size:14px">REQUIRED</span> | | ||
| :-------------------------------------------------- | :------------------------------------------------------ | | ||
| boolean | Yes | |
11 changes: 11 additions & 0 deletions
11
app/component-library/components/Checkbox/__snapshots__/Checkbox.test.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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Checkbox should render correctly 1`] = ` | ||
<Icon | ||
color="#037DD6" | ||
name="CheckBoxOnFilled" | ||
size="24" | ||
style={Object {}} | ||
testID="checkbox-icon" | ||
/> | ||
`; |
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 @@ | ||
export { default } from './Checkbox'; |
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
3 changes: 3 additions & 0 deletions
3
app/component-library/components/Icon/assets/check-box-off-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
app/component-library/components/Icon/assets/check-box-on-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
app/component-library/components/Icon/assets/check-circle-off-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
app/component-library/components/Icon/assets/check-circle-on-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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