Skip to content

Commit 96b4977

Browse files
Feat/snippets (#1823)
* Adding "snippet" key for uilib code snippet extension * more snippet keys * more snippets - tabcontroller and incubator * docs site - adding code snippet from new "snippet" key * Update scripts/build-docs.js Co-authored-by: Ethan Sharabi <[email protected]> * Update scripts/build-docs.js Co-authored-by: Ethan Sharabi <[email protected]> * Adding values to snippets Co-authored-by: Ethan Sharabi <[email protected]>
1 parent 974d786 commit 96b4977

File tree

68 files changed

+350
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+350
-6
lines changed

demo/src/screens/componentScreens/CardScannerScreen.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export default class CardScannerScreen extends Component {
5656
<View paddingL-40 marginB-20>
5757
<AnimatedScanner
5858
backgroundColor={Colors.purple30}
59-
progress={98} duration={1600}
59+
progress={98}
60+
duration={1600}
6061
containerStyle={{backgroundColor: Colors.violet50, height: 6}}
6162
/>
6263
</View>

scripts/build-docs.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
const _ = require('lodash');
12
const childProcess = require('child_process');
23
const fs = require('fs');
3-
const _ = require('lodash');
44

55
const COMPONENTS_DOCS_DIR = './docs/components';
66

@@ -43,7 +43,7 @@ components.forEach(component => {
4343
/* General */
4444
content += `${component.description} \n`;
4545
content += `[(code example)](${component.example})\n`;
46-
46+
4747
if (component.extends) {
4848
let extendsText = component.extends?.join(', ');
4949
if (component.extendsLink) {
@@ -70,13 +70,22 @@ components.forEach(component => {
7070
}
7171

7272
/* Images */
73-
content += `<div style={{display: 'flex', flexDirection: 'row', overflowX: 'auto', maxHeight: '500px', alignItems: 'center'}}>`;
73+
content +=
74+
`<div style={{display: 'flex', flexDirection: 'row', overflowX: 'auto', maxHeight: '500px', alignItems: 'center'}}>`;
7475
component.images?.forEach(image => {
7576
content += `<img style={{maxHeight: '420px'}} src={'${image}'}/>`;
7677
content += '\n\n';
7778
});
7879
content += '</div>\n\n';
7980

81+
/* Snippet */
82+
if (component.snippet) {
83+
content += `### Usage\n`;
84+
content += '```\n';
85+
content += component.snippet?.map(item => _.replace(item, new RegExp(/\$[1-9]/, 'g'), '')).join('\n');
86+
content += '\n```\n';
87+
}
88+
8089
/* Props */
8190
content += `## API\n`;
8291
_.sortBy(component.props, p => p.name)?.forEach(prop => {

src/components/actionBar/actionBar.api.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@
2424
"default": "true"
2525
},
2626
{"name": "style", "type": "ViewStyle", "description": "Component's style"}
27+
],
28+
"snippet": [
29+
"<ActionBar",
30+
" actions={[",
31+
" {label: 'Delete'$1, onPress: () => console.log('delete')$2},",
32+
" {label: $3, onPress: $4},",
33+
" {label: $5, onPress: $6}",
34+
" ]}",
35+
"/>"
2736
]
2837
}

src/components/actionSheet/actionSheet.api.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,18 @@
7171
"description": "In iOS, use safe area, in case component attached to the bottom"
7272
},
7373
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
74+
],
75+
"snippet": [
76+
"<ActionSheet",
77+
" title={'Title'$1}",
78+
" message={'Message goes here'$2}",
79+
" cancelButtonIndex={3$3}",
80+
" destructiveButtonIndex={0$4}",
81+
" options={[",
82+
" {label: '$5', onPress: $6},",
83+
" {label: '$7', onPress: $8},",
84+
" {label: 'Cancel', onPress: () => console.log('cancel')$9}",
85+
" ]}",
86+
"/>"
7487
]
7588
}

src/components/animatedImage/animatedImage.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
},
1616
{"name": "loader", "type": "JSX.element", "description": "A component to render while the image is loading"},
1717
{"name": "containerStyle", "type": "ViewStyle", "description": "Additional spacing styles for the container"}
18+
],
19+
"snippet": [
20+
"<AnimatedImage source={{uri: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/images/card-example.jpg$1}}/>"
1821
]
1922
}

src/components/animatedScanner/animatedScanner.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
{"name": "onBreakpoint", "type": "({progress, isDone}) => void", "description": "Breakpoint callback"},
2020
{"name": "hideScannerLine", "type": "boolean", "description": "Whether to hide the scanner line"},
2121
{"name": "containerStyle", "type": "ViewStyle", "description": "Component's container style"}
22+
],
23+
"snippet": [
24+
"<AnimatedScanner progress={55$1} duration={1600$2}/>"
2225
]
2326
}

src/components/avatar/avatar.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,8 @@
8585
{"name": "size", "type": " number", "description": "Custom size for the Avatar", "default": "50"},
8686
{"name": "onPress", "type": "(props: any) => void", "description": "Press handler"},
8787
{"name": "testID", "type": "string", "description": "Test identifier"}
88+
],
89+
"snippet": [
90+
"<Avatar source={{uri: 'https://lh3.googleusercontent.com/-cw77lUnOvmI/AAAAAAAAAAI/AAAAAAAAAAA/WMNck32dKbc/s181-c/104220521160525129167.jpg'$1}} label={IT$2}/>"
8891
]
8992
}

src/components/badge/badge.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@
3939
{"name": "iconProps", "type": "ImageProps", "description": "Additional props passed to icon"},
4040
{"name": "customElement", "type": "JSX.Element", "description": "Custom element to render instead of an icon"},
4141
{"name": "containerStyle", "type": "ViewStyle", "description": "Additional styles for the top container"}
42+
],
43+
"snippet": [
44+
"<Badge label={'999'$1} size={16$2}/>"
4245
]
4346
}

src/components/button/button.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@
6666
"type": "ButtonAnimationDirection",
6767
"description": "the direction of the animation ('left' and 'right' will effect the button's own alignment)"
6868
}
69+
],
70+
"snippet": [
71+
"<Button label={'Press'$1} size={Button.sizes.medium$2} backgroundColor={Colors.red30$3}/>"
6972
]
7073
}

src/components/card/card.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
"type": "CardSelectionOptions",
4242
"description": "Custom options for styling the selection indication"
4343
}
44+
],
45+
"snippet": [
46+
"<Card flex center onPress={() => console.log('pressed')}$1>",
47+
" <Card.Image source={{uri: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/images/card-example.jpg}}/>$2",
48+
"</Card>"
4449
]
4550
}

src/components/card/cardImage.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"type": "string[]",
1414
"description": "The Image position which determines the appropriate flex-ness of the image and border radius (for Android) this prop derived automatically from Card parent component if it rendered as a direct child of the Card component"
1515
}
16+
],
17+
"snippet": [
18+
"<Card.Image source={{uri: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/images/card-example.jpg$1}} height={115$2}/>"
1619
]
1720
}

src/components/card/cardSection.api.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@
3030
},
3131
{"name": "imageStyle", "type": "ImageStyle", "description": "The style for the background image"},
3232
{"name": "imageProps", "type": "ImageProps", "description": "Other image props that will be passed to the image"}
33+
],
34+
"snippet": [
35+
"<Card.Section",
36+
" content={[{text: 'Card content here', text70: true, grey10: true}]$1}",
37+
" contentStyle={{alignItems: 'center'}$2}",
38+
"/>"
3339
]
3440
}

src/components/carousel/carousel.api.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,12 @@
9292
"type": "Animated.ValueXY",
9393
"description": "Pass to attach to ScrollView's Animated.event in order to animated elements base on Carousel scroll offset (pass new Animated.ValueXY())"
9494
}
95+
],
96+
"snippet": [
97+
"<Carousel onChangePage={() => console.log('page changed')$1}>",
98+
" {_.map(items, item => (",
99+
" return this.renderItem(item, index);",
100+
" ))}",
101+
"</Carousel>"
95102
]
96103
}

src/components/checkbox/checkbox.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
"type": "ViewStyle",
3636
"description": "Custom styling for the checkbox and label container"
3737
}
38+
],
39+
"snippet": [
40+
"<Checkbox value={false$1} onValueChange={() => console.log('value changed’)$2}/>"
3841
]
3942
}

src/components/chip/chip.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,8 @@
5151
{"name": "dismissIconStyle", "type": "ImageStyle", "description": "Dismiss style"},
5252
{"name": "dismissContainerStyle", "type": "ImageStyle", "description": "Dismiss container style"},
5353
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
54+
],
55+
"snippet": [
56+
"<Chip label={'Chip'$1} onPress={() => console.log('pressed’)$2}/>"
5457
]
5558
}

src/components/chipsInput/chipsInput.api.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,11 @@
7373
{"name": "value", "type": "any", "description": "The input's value"},
7474
{"name": "selectionColor", "type": "string | number", "description": "The color for the selection state"},
7575
{"name": "containerStyle", "type": "ViewStyle", "description": "Component's container style"}
76+
],
77+
"snippet": [
78+
"<ChipsInput",
79+
" placeholder={'Placeholder'$1}",
80+
" chips={[{label: 'Falcon 9'}, {label: 'Enterprise'}, {label: 'Challenger', borderRadius: 0}]$2}",
81+
"/>"
7682
]
7783
}

src/components/colorPalette/ColorPalette.api.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,12 @@
3939
{"name": "containerStyle", "type": "ViewStyle", "description": "Component's container style"},
4040
{"name": "style", "type": "ViewStyle", "description": "Component's style"},
4141
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
42+
],
43+
"snippet": [
44+
"<ColorPalette",
45+
" colors={['transparent', Colors.green30, Colors.yellow30, Colors.red30]$1}",
46+
" value={this.state.selectedColor$2}",
47+
" onValueChange={() => console.log('value changed)$3}",
48+
"/>"
4249
]
4350
}

src/components/colorPicker/colorPicker.api.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,15 @@
3333
},
3434
{"name": "style", "type": "ViewStyle", "description": "Component's style"},
3535
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
36+
],
37+
"snippet": [
38+
"<ColorPicker",
39+
" colors={[Colors.green10, Colors.green20, Colors.green30, Colors.green40, Colors.green50, Colors.green60, Colors.green70]$1}",
40+
" initialColor={Colors.green10$2}",
41+
" value={this.state.color$3}",
42+
" onDismiss={() => console.log('dismissed')$4}",
43+
" onSubmit={() => console.log('submit')$5}",
44+
" onValueChange={() => console.log('value changed')$6}",
45+
"/>"
3646
]
3747
}

src/components/colorSwatch/colorSwatch.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@
2020
{"name": "index", "type": "number", "description": "The index of the Swatch if in array"},
2121
{"name": "style", "type": "ViewStyle", "description": "Component's style"},
2222
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
23+
],
24+
"snippet": [
25+
"<ColorSwatch color={Colors.red30$1} selected={true$2} onPress={() => console.log('pressed')$3}/>"
2326
]
2427
}

src/components/connectionStatusBar/connectionStatusBar.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"description": "Use absolute position for the component",
3131
"default": "true"
3232
}
33+
],
34+
"snippet": [
35+
"<ConnectionStatusBar onConnectionChange={() => console.log('connection changed')$1}/>"
3336
]
3437
}

src/components/dateTimePicker/dateTimePicker.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@
6161
"type": "LIGHT | DARK",
6262
"description": "Override system theme variant (dark or light mode) used by the date picker"
6363
}
64+
],
65+
"snippet": [
66+
"<DateTimePicker title={'Select time'$1} placeholder={'Placeholder'$2} mode={'time'$3}/>"
6467
]
6568
}

src/components/dialog/dialog.api.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,14 @@
4747
},
4848
{"name": "containerStyle", "type": "ViewStyle", "description": "Component's container style"},
4949
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
50+
],
51+
"snippet": [
52+
"<Dialog",
53+
" visible={this.state.visible$1}",
54+
" onDismiss={() => console.log('dismissed')$2}",
55+
" panDirection={PanningProvider.Directions.DOWN$3}",
56+
">",
57+
" {<Text text60>Content</Text>}$4",
58+
"</Dialog>"
5059
]
5160
}

src/components/drawer/drawer.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,10 @@
5757
},
5858
{"name": "style", "type": "ViewStyle", "description": "Component's style"},
5959
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
60+
],
61+
"snippet": [
62+
"<Drawer rightItems:{[{text: 'Read', onPress: () => console.log('read pressed')}, {text: 'Delete', onPress: () => console.log('delete pressed')}]}$1>",
63+
" <ListItem><Text grey10 text60 marginL-10>The item</Text></ListItem>$2",
64+
"</Drawer>"
6065
]
6166
}

src/components/expandableSection/expandableSection.api.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@
1212
{"name": "expanded", "type": "boolean", "description": "Should the ExpandableSection be expanded"},
1313
{"name": "top", "type": "boolean", "description": "Should it open above the 'sectionHeader'"},
1414
{"name": "onPress", "type": "() => void", "description": "Called when pressing the header of the ExpandableSection"}
15+
],
16+
"snippet": [
17+
"<ExpandableSection",
18+
" top={true$1}",
19+
" expanded={false$2}",
20+
" sectionHeader={<Text grey10 text60>The section header</Text>$3}",
21+
" onPress={() => console.log('pressed')$4}",
22+
">"
1523
]
1624
}

src/components/fader/fader.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"description": "Change the tint color of the fade view",
2020
"default": "Colors.white"
2121
}
22+
],
23+
"snippet": [
24+
"<Fader visible={this.state.visible$1} position={Fader.position.BOTTOM$2}/>"
2225
]
2326
}

src/components/featureHighlight/featureHighlight.api.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,15 @@
6767
},
6868
{"name": "pageControlProps", "type": "PageControlProps", "description": "PageControl component's props"},
6969
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
70+
],
71+
"snippet": [
72+
"<FeatureHighlight",
73+
" visible={this.state.visible$1}",
74+
" title={'Title'$2}",
75+
" message={'Message goes here'$3}",
76+
" getTarget={targets[this.state.currentTarget]$4}",
77+
" confirmButtonProps={{label: 'Got It', onPress: () => console.log('confirmed')}$5}",
78+
" onBackgroundPress={() => console.log('background pressed')$6}",
79+
"/>"
7080
]
7181
}

src/components/floatingButton/floatingButton.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"description": "The test id for e2e tests",
2626
"note": "<TestID> - the floatingButton container\n<TestID>.button - the floatingButton main button\n<TestID>.secondaryButton - the floatingButton secondaryButton"
2727
}
28+
],
29+
"snippet": [
30+
"<FloatingButton visible={this.state.visible$1} button={button={{label: 'Approve', onPress: () => console.log('approved')}}$2}/>"
2831
]
2932
}

src/components/gridListItem/gridListItem.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848
"description": "Renders an overlay on top of the image"
4949
},
5050
{"name": "testID", "type": "string", "description": "Test ID for component"}
51+
],
52+
"snippet": [
53+
"<GridListItem key={index$1} title={'Title'$2} subtitle={'Subtitle'$3} description={'Description goes here'$4}/>"
5154
]
5255
}

src/components/gridView/gridView.api.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,12 @@
2424
"type": "(item: GridListItemProps) => React.ReactElement",
2525
"description": "Pass to render a custom item"
2626
}
27+
],
28+
"snippet": [
29+
"<GridView",
30+
" items={[{title: 'item 1', onPress: () => console.log('item 1 pressed')}, {title: 'item 2', onPress: () => console.log('item 2 pressed')}, ]$1}",
31+
" numColumns={2$2}",
32+
" lastItemLabel={'+'$3}",
33+
"/>"
2734
]
2835
}

src/components/hint/hint.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848
{"name": "enableShadow", "type": "boolean", "description": "Enable shadow (for hint with white background only)"},
4949
{"name": "testID", "type": "string", "description": "The hint's test identifier"},
5050
{"name": "style", "type": "ViewStyle", "description": "Additional styling"}
51+
],
52+
"snippet": [
53+
"<Hint visible={this.state.visible$1} message={'Message goes here'$2} color={Colors.red30$3}/>"
5154
]
5255
}

src/components/icon/icon.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
{"name": "tintColor", "type": "string", "description": "The icon tint"},
1313
{"name": "size", "type": "number", "description": "The icon size"},
1414
{"name": "supportRTL", "type": "boolean", "description": "whether the image should flip horizontally on RTL locals"}
15+
],
16+
"snippet": [
17+
"<Icon source={{uri: 'https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/icons/delete.png'}$1} size={24$2} tintColor={Colors.grey40$3}/>"
1518
]
1619
}

src/components/image/image.api.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@
4242
{"name": "overlayColor", "type": "string", "description": "Pass a custom color for the overlay"},
4343
{"name": "customOverlayContent", "type": "JSX.Element", "description": "Render an overlay with custom content"},
4444
{"name": "errorSource", "type": "ImageSourcePropType", "description": "Default image source in case of an error"}
45+
],
46+
"snippet": [
47+
"<Image source={{uri: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/assets/images/card-example.jpg}}/>"
4548
]
4649
}

src/components/listItem/listItem.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@
1919
{"name": "style", "type": "ViewStyle", "description": "The inner element style"},
2020
{"name": "underlayColor", "type": "string", "description": "The inner element pressed backgroundColor"},
2121
{"name": "testID", "type": "string", "description": "The test id for e2e tests"}
22+
],
23+
"snippet": [
24+
"<ListItem onPress={() => console.log('pressed)$1}>",
25+
" <Text grey10 text60 marginL-10>The item</Text>$2",
26+
"</ListItem>"
2227
]
2328
}

0 commit comments

Comments
 (0)