Skip to content

Commit 5a9f4c8

Browse files
committed
Reorder examples in docs for Select components
1 parent 452e065 commit 5a9f4c8

File tree

3 files changed

+156
-151
lines changed

3 files changed

+156
-151
lines changed

packages/react-components/source/react/library/action-select/ActionSelect.md

+49-47
Original file line numberDiff line numberDiff line change
@@ -171,52 +171,6 @@ const style = { display: 'inline-block', margin: 10 };
171171
</div>;
172172
```
173173

174-
### Icons
175-
176-
Specify the `icon` prop on each option to display a supported icon to the left of that option, or use the `svg` prop to use a custom icon.
177-
178-
```jsx
179-
const customIcon = {
180-
viewBox: '0 0 16 16',
181-
svg: (
182-
<path
183-
fill="#818f99"
184-
fillRule="evenodd"
185-
d="M8 .2A8 8 0 0 0 5.47 15.79c.4.074.546-.173.546-.385 0-.19-.007-.693-.01-1.36-2.226.483-2.695-1.073-2.695-1.073-.364-.924-.889-1.17-.889-1.17-.726-.496.055-.486.055-.486.803.056 1.226.824 1.226.824.713 1.222 1.872.87 2.328.665.073-.517.279-.87.508-1.07-1.777-.201-3.644-.888-3.644-3.953 0-.874.312-1.588.823-2.147-.082-.202-.357-1.016.078-2.117 0 0 .672-.215 2.2.82A7.662 7.662 0 0 1 8 4.068c.68.004 1.364.092 2.003.27 1.527-1.035 2.198-.82 2.198-.82.436 1.101.162 1.915.08 2.117.512.56.822 1.273.822 2.147 0 3.073-1.87 3.75-3.653 3.947.287.247.543.735.543 1.482 0 1.069-.01 1.932-.01 2.194 0 .214.144.463.55.385A8 8 0 0 0 8 .2"
186-
/>
187-
),
188-
};
189-
190-
const actions = [
191-
{
192-
id: 'custom-icon',
193-
svg: customIcon.svg,
194-
label: 'GitHub',
195-
onClick() {
196-
console.log('GitHub');
197-
},
198-
},
199-
{
200-
id: 'standard-icon',
201-
icon: 'question-circle',
202-
label: 'Other',
203-
onClick() {
204-
console.log('Other');
205-
},
206-
},
207-
];
208-
209-
const style = { display: 'inline-block', margin: 10 };
210-
211-
<div>
212-
<ActionSelect
213-
actions={actions}
214-
label="Choose a source control"
215-
style={style}
216-
/>
217-
</div>;
218-
```
219-
220174
### Custom Width
221175

222176
Use the `width` prop to customize the width of the button.
@@ -261,7 +215,9 @@ const style = { display: 'inline-block', margin: 10 };
261215
</div>;
262216
```
263217

264-
### Disable rows
218+
## Action properties
219+
220+
### Disabled actions
265221

266222
Use the `disabled` object property to disable a row in a dropdown and prevent onClick actions from happening.
267223

@@ -301,6 +257,52 @@ const style = { display: 'inline-block', margin: 10 };
301257
</div>;
302258
```
303259

260+
### Icons
261+
262+
Specify the `icon` prop on each action to display a supported icon to the left of that option, or use the `svg` prop to use a custom icon.
263+
264+
```jsx
265+
const customIcon = {
266+
viewBox: '0 0 16 16',
267+
svg: (
268+
<path
269+
fill="#818f99"
270+
fillRule="evenodd"
271+
d="M8 .2A8 8 0 0 0 5.47 15.79c.4.074.546-.173.546-.385 0-.19-.007-.693-.01-1.36-2.226.483-2.695-1.073-2.695-1.073-.364-.924-.889-1.17-.889-1.17-.726-.496.055-.486.055-.486.803.056 1.226.824 1.226.824.713 1.222 1.872.87 2.328.665.073-.517.279-.87.508-1.07-1.777-.201-3.644-.888-3.644-3.953 0-.874.312-1.588.823-2.147-.082-.202-.357-1.016.078-2.117 0 0 .672-.215 2.2.82A7.662 7.662 0 0 1 8 4.068c.68.004 1.364.092 2.003.27 1.527-1.035 2.198-.82 2.198-.82.436 1.101.162 1.915.08 2.117.512.56.822 1.273.822 2.147 0 3.073-1.87 3.75-3.653 3.947.287.247.543.735.543 1.482 0 1.069-.01 1.932-.01 2.194 0 .214.144.463.55.385A8 8 0 0 0 8 .2"
272+
/>
273+
),
274+
};
275+
276+
const actions = [
277+
{
278+
id: 'custom-icon',
279+
svg: customIcon.svg,
280+
label: 'GitHub',
281+
onClick() {
282+
console.log('GitHub');
283+
},
284+
},
285+
{
286+
id: 'standard-icon',
287+
icon: 'question-circle',
288+
label: 'Other',
289+
onClick() {
290+
console.log('Other');
291+
},
292+
},
293+
];
294+
295+
const style = { display: 'inline-block', margin: 10 };
296+
297+
<div>
298+
<ActionSelect
299+
actions={actions}
300+
label="Choose a source control"
301+
style={style}
302+
/>
303+
</div>;
304+
```
305+
304306
## Related
305307

306308
- [ButtonSelect](#/React%20Components/ButtonSelect)

packages/react-components/source/react/library/button-select/ButtonSelect.md

+71-69
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,6 @@ const options = [
2424
/>;
2525
```
2626

27-
### Disable rows
28-
29-
Use the `disabled` object property to disable a row in a dropdown and prevent onClick actions from happening.
30-
31-
```jsx
32-
const options = [
33-
{ value: 'hello', label: 'Hello' },
34-
{ value: 'world', label: 'World' },
35-
{ value: 'hi', label: 'Hi', disabled: true },
36-
{ value: 'mom', label: 'Mom', disabled: true },
37-
];
38-
39-
<ButtonSelect
40-
options={options}
41-
value={state.value}
42-
onChange={value => {
43-
console.log('New Value:', value);
44-
setState({ value });
45-
}}
46-
/>;
47-
```
48-
4927
## Types
5028

5129
The visual types of `ButtonSelect` are "primary", "secondary", "tertiary", "danger", "transparent", "text".
@@ -133,25 +111,29 @@ const style = { display: 'inline-block', margin: 10 };
133111

134112
## Variations
135113

136-
### Custom selected labels
114+
### Multiple selections
137115

138-
An alternate `selectedLabel` prop can be specified on each option.
116+
Multiple values can be selected if the `multiple` prop is `true`. In this mode an "Apply" button will render below the options list. The newly selected values are not applied until the user activates this button. If the user clicks the "Cancel" button, presses escape, or click out of the open menu, their changes will be discarded.
139117

140118
```jsx
141119
initialState = {
142-
value: 'name',
120+
value: [],
143121
};
144122

145123
const options = [
146-
{ value: 'name', label: 'Name', selectedLabel: 'Sort by name' },
147-
{ value: 'date', label: 'Date', selectedLabel: 'Sort by date' },
124+
{ value: 'one', label: 'One' },
125+
{ value: 'two', label: 'Two' },
126+
{ value: 'three', label: 'Three' },
127+
{ value: 'four', label: 'Four' },
128+
{ value: 'five', label: 'Five' },
129+
{ value: 'six', label: 'Six' },
148130
];
149131

150132
const style = { display: 'inline-block', margin: 10 };
151133

152134
<div>
153135
<ButtonSelect
154-
type="tertiary"
136+
multiple
155137
options={options}
156138
placeholder="Select multiple things"
157139
style={style}
@@ -164,9 +146,11 @@ const style = { display: 'inline-block', margin: 10 };
164146
</div>;
165147
```
166148

167-
### Multiple selections
149+
### Multiple selections, immediately applied
168150

169-
Multiple values can be selected if the `multiple` prop is `true`. In this mode an "Apply" button will render below the options list. The newly selected values are not applied until the user activates this button. If the user clicks the "Cancel" button, presses escape, or click out of the open menu, their changes will be discarded.
151+
Warning: Consult with your UX designer prior to using this option. We are considering deprecating this behavior in order to simplify multi-select menus.
152+
153+
The default multi-select behavior can be overridden with the `applyImmediately` prop. In this mode, a 'Done' button will still render for consistency but the values will be immediately applied. If the user escapes or clicks out of the open menu, their changes will be discarded.
170154

171155
```jsx
172156
initialState = {
@@ -180,13 +164,19 @@ const options = [
180164
{ value: 'four', label: 'Four' },
181165
{ value: 'five', label: 'Five' },
182166
{ value: 'six', label: 'Six' },
167+
{ value: 'seven', label: 'Seven' },
168+
{ value: 'eight', label: 'Eight' },
169+
{ value: 'nine', label: 'Nine' },
170+
{ value: 'ten', label: 'Ten' },
183171
];
184172

185173
const style = { display: 'inline-block', margin: 10 };
186174

187175
<div>
188176
<ButtonSelect
177+
type="tertiary"
189178
multiple
179+
applyImmediately
190180
options={options}
191181
placeholder="Select multiple things"
192182
style={style}
@@ -199,37 +189,50 @@ const style = { display: 'inline-block', margin: 10 };
199189
</div>;
200190
```
201191

202-
### Multiple selections, immediately applied
192+
### Custom Width
203193

204-
Warning: Consult with your UX designer prior to using this option. We are considering deprecating this behavior in order to simplify multi-select menus.
194+
Use the `width` prop to customize the width of the button.
205195

206-
The default multi-select behavior can be overridden with the `applyImmediately` prop. In this mode, a 'Done' button will still render for consistency but the values will be immediately applied. If the user escapes or clicks out of the open menu, their changes will be discarded.
196+
```jsx
197+
const options = [
198+
{ value: 'hello', label: 'Hello' },
199+
{ value: 'world', label: 'World' },
200+
{ value: 'hi', label: 'Hi' },
201+
{ value: 'mom', label: 'Mom' },
202+
];
203+
204+
<ButtonSelect
205+
options={options}
206+
value={state.value}
207+
onChange={value => {
208+
console.log('New Value:', value);
209+
setState({ value });
210+
}}
211+
width="100px"
212+
/>;
213+
```
214+
215+
## Option properties
216+
217+
### Custom selected labels
218+
219+
An alternate `selectedLabel` prop can be specified on each option.
207220

208221
```jsx
209222
initialState = {
210-
value: [],
223+
value: 'name',
211224
};
212225

213226
const options = [
214-
{ value: 'one', label: 'One' },
215-
{ value: 'two', label: 'Two' },
216-
{ value: 'three', label: 'Three' },
217-
{ value: 'four', label: 'Four' },
218-
{ value: 'five', label: 'Five' },
219-
{ value: 'six', label: 'Six' },
220-
{ value: 'seven', label: 'Seven' },
221-
{ value: 'eight', label: 'Eight' },
222-
{ value: 'nine', label: 'Nine' },
223-
{ value: 'ten', label: 'Ten' },
227+
{ value: 'name', label: 'Name', selectedLabel: 'Sort by name' },
228+
{ value: 'date', label: 'Date', selectedLabel: 'Sort by date' },
224229
];
225230

226231
const style = { display: 'inline-block', margin: 10 };
227232

228233
<div>
229234
<ButtonSelect
230235
type="tertiary"
231-
multiple
232-
applyImmediately
233236
options={options}
234237
placeholder="Select multiple things"
235238
style={style}
@@ -242,6 +245,28 @@ const style = { display: 'inline-block', margin: 10 };
242245
</div>;
243246
```
244247

248+
### Disabled options
249+
250+
Use the `disabled` object property to disable a row in a dropdown.
251+
252+
```jsx
253+
const options = [
254+
{ value: 'hello', label: 'Hello' },
255+
{ value: 'world', label: 'World' },
256+
{ value: 'hi', label: 'Hi', disabled: true },
257+
{ value: 'mom', label: 'Mom', disabled: true },
258+
];
259+
260+
<ButtonSelect
261+
options={options}
262+
value={state.value}
263+
onChange={value => {
264+
console.log('New Value:', value);
265+
setState({ value });
266+
}}
267+
/>;
268+
```
269+
245270
### Icons
246271

247272
Specify the `icon` prop on each option to display a supported icon to the left of that option, or use the `svg` prop to use a custom icon.
@@ -282,26 +307,3 @@ const options = [
282307
/>
283308
</div>;
284309
```
285-
286-
### Custom Width
287-
288-
Use the `width` prop to customize the width of the button.
289-
290-
```jsx
291-
const options = [
292-
{ value: 'hello', label: 'Hello' },
293-
{ value: 'world', label: 'World' },
294-
{ value: 'hi', label: 'Hi' },
295-
{ value: 'mom', label: 'Mom' },
296-
];
297-
298-
<ButtonSelect
299-
options={options}
300-
value={state.value}
301-
onChange={value => {
302-
console.log('New Value:', value);
303-
setState({ value });
304-
}}
305-
width="100px"
306-
/>;
307-
```

0 commit comments

Comments
 (0)