|
| 1 | +--- |
| 2 | +order: 12 |
| 3 | +--- |
| 4 | + |
| 5 | +# Button groups in forms |
| 6 | + |
| 7 | +<EuiText> |
| 8 | +<p>When using button groups within compressed forms, match the form elements by adding <EuiCode>buttonSize="compressed"</EuiCode>. Compressed groups should always be <EuiCode>fullWidth</EuiCode> so they line up nicely in their small container <strong>unless</strong> they are icon only. |
| 9 | +</p> |
| 10 | + |
| 11 | +</EuiText> |
| 12 | + |
| 13 | +```hbs template |
| 14 | +<EuiPanel @hasBorder={{true}} style='max-width: 300px'> |
| 15 | + <EuiButtonGroup |
| 16 | + @name='coarsness' |
| 17 | + @legend='This is a basic group' |
| 18 | + @options={{this.toggleButtonsCompressed}} |
| 19 | + @idSelected={{this.toggleCompressedIdSelected}} |
| 20 | + @onChange={{set this 'toggleCompressedIdSelected'}} |
| 21 | + @buttonSize='compressed' |
| 22 | + @isFullWidth={{true}} |
| 23 | + /> |
| 24 | + <EuiSpacer /> |
| 25 | + <EuiButtonGroup |
| 26 | + @legend='Text style' |
| 27 | + class='eui-displayInlineBlock' |
| 28 | + @options={{this.toggleButtonsIconsMulti}} |
| 29 | + @idToSelectedMap={{this.toggleIconIdToSelectedMapIcon}} |
| 30 | + @onChange={{this.onChangeMulti}} |
| 31 | + @type='multi' |
| 32 | + @buttonSize='compressed' |
| 33 | + @isIconOnly={{true}} |
| 34 | + /> |
| 35 | +</EuiPanel> |
| 36 | +``` |
| 37 | + |
| 38 | +```js component |
| 39 | +import Component from '@glimmer/component'; |
| 40 | +import { guidFor } from '@ember/object/internals'; |
| 41 | +import { tracked } from '@glimmer/tracking'; |
| 42 | + |
| 43 | +const idPrefix3 = guidFor({}); |
| 44 | +export default class extends Component { |
| 45 | + @tracked toggleCompressedIdSelected = `${idPrefix3}__1`; |
| 46 | + @tracked toggleIconIdToSelectedMapIcon = {}; |
| 47 | + |
| 48 | + toggleButtonsCompressed = [ |
| 49 | + { |
| 50 | + id: `${idPrefix3}__0`, |
| 51 | + label: 'fine' |
| 52 | + }, |
| 53 | + { |
| 54 | + id: `${idPrefix3}__1`, |
| 55 | + label: 'rough' |
| 56 | + }, |
| 57 | + { |
| 58 | + id: `${idPrefix3}__2`, |
| 59 | + label: 'coarse' |
| 60 | + } |
| 61 | + ]; |
| 62 | + |
| 63 | + toggleButtonsIconsMulti = [ |
| 64 | + { |
| 65 | + id: `${idPrefix3}__multi__0`, |
| 66 | + label: 'Bold', |
| 67 | + name: 'bold', |
| 68 | + iconType: 'editorBold' |
| 69 | + }, |
| 70 | + { |
| 71 | + id: `${idPrefix3}__multi__1`, |
| 72 | + label: 'Italic', |
| 73 | + name: 'italic', |
| 74 | + iconType: 'editorItalic', |
| 75 | + isDisabled: true |
| 76 | + }, |
| 77 | + { |
| 78 | + id: `${idPrefix3}__multi__2`, |
| 79 | + label: 'Underline', |
| 80 | + name: 'underline', |
| 81 | + iconType: 'editorUnderline' |
| 82 | + }, |
| 83 | + { |
| 84 | + id: `${idPrefix3}__multi__3`, |
| 85 | + label: 'Strikethrough', |
| 86 | + name: 'strikethrough', |
| 87 | + iconType: 'editorStrike' |
| 88 | + } |
| 89 | + ]; |
| 90 | + |
| 91 | + onChangeMulti = (optionId) => { |
| 92 | + const newtoggleIconIdToSelectedMapIcon = { |
| 93 | + ...this.toggleIconIdToSelectedMapIcon, |
| 94 | + ...{ |
| 95 | + [optionId]: !this.toggleIconIdToSelectedMapIcon[optionId] |
| 96 | + } |
| 97 | + }; |
| 98 | + this.toggleIconIdToSelectedMapIcon = newtoggleIconIdToSelectedMapIcon; |
| 99 | + }; |
| 100 | +} |
| 101 | +``` |
0 commit comments