From 1b5e4cad61a33fd1f430aa7b9ebbd914dd4d2e15 Mon Sep 17 00:00:00 2001 From: Artur Bien Date: Mon, 30 Nov 2020 22:58:19 +0100 Subject: [PATCH] feat(select): add select component --- example/src/examples/SelectExample.tsx | 34 ++++ example/src/examples/index.tsx | 2 + src/Panel/Panel.tsx | 2 +- src/Select/Select.tsx | 255 +++++++++++++++++++++++++ src/Select/index.ts | 1 + src/common/styles.ts | 5 + src/index.ts | 1 + 7 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 example/src/examples/SelectExample.tsx create mode 100644 src/Select/Select.tsx create mode 100644 src/Select/index.ts diff --git a/example/src/examples/SelectExample.tsx b/example/src/examples/SelectExample.tsx new file mode 100644 index 0000000..3395dfe --- /dev/null +++ b/example/src/examples/SelectExample.tsx @@ -0,0 +1,34 @@ +import React, { useState } from 'react'; +import { Panel, Select, Fieldset } from 'react95-native'; + +const options = ['apple', 'orange', 'banana', 'pear', 'watermelon'].map(o => ({ + label: o, + value: o, +})); + +const SelectExample = () => { + const [value, setValue] = useState(options[0].value); + return ( + +
+ setValue(newValue)} + style={[{ width: 150 }]} + /> +
+
+ ); +}; + +export default SelectExample; diff --git a/example/src/examples/index.tsx b/example/src/examples/index.tsx index 3ed4146..8095441 100644 --- a/example/src/examples/index.tsx +++ b/example/src/examples/index.tsx @@ -11,6 +11,7 @@ import WindowExample from './WindowExample'; import FieldsetExample from './FieldsetExample'; import MenuExample from './MenuExample'; import ProgressExample from './ProgressExample'; +import SelectExample from './SelectExample'; export default [ { name: 'ButtonExample', component: ButtonExample, title: 'Button' }, @@ -26,6 +27,7 @@ export default [ { name: 'FieldsetExample', component: FieldsetExample, title: 'Fieldset' }, { name: 'MenuExample', component: MenuExample, title: 'Menu' }, { name: 'ProgressExample', component: ProgressExample, title: 'Progress' }, + { name: 'SelectExample', component: SelectExample, title: 'Select' }, ].sort((a, b) => { /* Sort screens alphabetically */ if (a.title < b.title) return -1; diff --git a/src/Panel/Panel.tsx b/src/Panel/Panel.tsx index 3e0f060..c3e5858 100644 --- a/src/Panel/Panel.tsx +++ b/src/Panel/Panel.tsx @@ -8,7 +8,7 @@ export const testId = 'panel'; // TODO: common interface with styleElements/Border ? type Props = { - children: React.ReactNode; + children?: React.ReactNode; variant?: 'default' | 'well' | 'outside'; style?: StyleProp; }; diff --git a/src/Select/Select.tsx b/src/Select/Select.tsx new file mode 100644 index 0000000..11798cd --- /dev/null +++ b/src/Select/Select.tsx @@ -0,0 +1,255 @@ +import React, { useState } from 'react'; +import { + StyleSheet, + View, + Text, + TouchableHighlight, + ImageBackground, +} from 'react-native'; +import { original as theme } from '../common/themes'; +import { blockSizes, text, border } from '../common/styles'; +import { Border } from '../common/styleElements'; + +type Option = { + value: any; + label: React.ReactNode; +}; + +type SelectItemProps = { + option: Option; + onPress: () => void; + isSelected: boolean; +}; + +const SelectItem = ({ option, onPress, isSelected }: SelectItemProps) => { + const [isPressed, setIsPressed] = useState(false); + + return ( + onPress(option)} + onHideUnderlay={() => setIsPressed(false)} + onShowUnderlay={() => setIsPressed(true)} + accessibilityRole='menuitem' + underlayColor='none' + > + + + {option.label} + + + + ); +}; + +const dropdownSymbol = { + default: + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAALElEQVQoU2NkIAIwEqGGgWRF/7GYCjYE3SRkhXA5bNaBFKKIk+wmnB4lyiQAAsgDCqkPxTcAAAAASUVORK5CYII=', + disabled: + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJCAYAAADgkQYQAAAANklEQVQoU2NkIAIwEqGGgTRFLa0t/9FNramuARuCYhKyQpgCDEUgAZBCZAVYFWHzCGkOxxcUANHnDAplQ9G1AAAAAElFTkSuQmCC', +}; + +type SelectProps = { + options: Array