-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fieldset): add fieldset component
- Loading branch information
Artur Bien
committed
Nov 28, 2020
1 parent
4059f20
commit 7e7e822
Showing
6 changed files
with
84 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { View, Text } from 'react-native'; | ||
import { Panel, Fieldset } from 'react95-native'; | ||
|
||
const DividerExample = () => { | ||
return ( | ||
<Panel style={{ flex: 1, padding: 20 }}> | ||
<Text style={{ marginBottom: 20 }}>Default</Text> | ||
<Fieldset label='Name:'> | ||
<Text style={[{ fontSize: 16 }]}>Some text here</Text> | ||
</Fieldset> | ||
<Fieldset> | ||
<Text style={[{ fontSize: 16 }]}>No label here</Text> | ||
</Fieldset> | ||
</Panel> | ||
); | ||
}; | ||
|
||
export default DividerExample; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { original as theme } from '../common/themes'; | ||
import { Border } from '../common/styleElements'; | ||
|
||
export const testId = 'fieldset'; | ||
|
||
type Props = { | ||
label: React.ReactNode; | ||
children: React.ReactNode; | ||
style?: Object; | ||
}; | ||
|
||
const Fieldset = ({ children, label, style = {} }: Props) => { | ||
return ( | ||
<View style={[styles.wrapper, style]} testID={testId}> | ||
<Border | ||
variant='well' | ||
invert | ||
style={[ | ||
{ marginLeft: 2, marginRight: 2, marginTop: 2, marginBottom: 2 }, | ||
]} | ||
/> | ||
<Border variant='well' /> | ||
{/* TODO: allow passing components to label (see web react95 checkbox example) */} | ||
{label && <Text style={[styles.label]}>{label}</Text>} | ||
{children} | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
wrapper: { | ||
position: 'relative', | ||
marginTop: 8, | ||
padding: 12, | ||
}, | ||
label: { | ||
position: 'absolute', | ||
top: 0, | ||
left: 8, | ||
// TODO: how to properly center the label? | ||
transform: [{ translateY: -8 }], | ||
paddingHorizontal: 8, | ||
backgroundColor: theme.material, | ||
fontSize: 16, | ||
lineHeight: 16, | ||
}, | ||
}); | ||
|
||
export default Fieldset; |
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 './Fieldset'; |
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