Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.x] feat: vertical oriented button group #1461

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src-docs/src/views/button/button_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ const buttonGroupIconsHtml = renderToHtml(ButtonGroupIcons);
import ButtonGroupCompressed from './button_group_compressed';
const buttonGroupCompressedSource = require('!!raw-loader!./button_group_compressed');
const buttonGroupCompressedHtml = renderToHtml(ButtonGroupCompressed);

import ButtonGroupVertical from './button_group_vertical';
const ButtonGroupVerticalSource = require('!!raw-loader!./button_group_vertical');
const ButtonGroupVerticalHtml = renderToHtml(ButtonGroupVertical);

const buttonGroupSnippet = [
`<OuiButtonGroup
type="single"
Expand Down Expand Up @@ -171,6 +176,23 @@ const buttonGroupIconsSnippet = [
/>`,
];

const ButtonGroupVerticalSnippet = [
`<OuiButtonGroup
orientation="vertical"
isIconOnly
legend={legend}
options={[
{
id,
label,
iconType,
}
]}
idToSelectedMap={{ optionId: true }}
onChange={(optionId, optionValue) => {}}
/>`,
];

export const ButtonExample = {
title: 'Button',
sections: [
Expand Down Expand Up @@ -469,6 +491,26 @@ export const ButtonExample = {
demo: <ButtonGroupIcons />,
snippet: buttonGroupIconsSnippet,
},
{
source: [
{
type: GuideSectionTypes.JS,
code: ButtonGroupVerticalSource,
},
{
type: GuideSectionTypes.HTML,
code: ButtonGroupVerticalHtml,
},
],
wrapText: false,
text: (
<OuiTitle size="xs">
<h3>Vertical orientated</h3>
</OuiTitle>
),
demo: <ButtonGroupVertical />,
snippet: ButtonGroupVerticalSnippet,
},
{
source: [
{
Expand Down
179 changes: 179 additions & 0 deletions src-docs/src/views/button/button_group_vertical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React, { useState, Fragment } from 'react';

import {
OuiButtonGroup,
OuiSpacer,
OuiTitle,
} from '../../../../src/components';

import { htmlIdGenerator } from '../../../../src/services';

const idPrefix = htmlIdGenerator()();
const idPrefix3 = htmlIdGenerator()();

export default () => {
const [toggleIdSelected, setToggleIdSelected] = useState(`${idPrefix}1`);

const onChange = (optionId) => {
setToggleIdSelected(optionId);
};

const toggleButtons = [
{
id: `${idPrefix}0`,
label: 'Option one',
},
{
id: `${idPrefix}1`,
label: 'Option two',
},
{
id: `${idPrefix}2`,
label: 'Option three',
},
];

const toggleButtonsIcons = [
{
id: `${idPrefix3}0`,
label: 'Align left',
iconType: 'editorAlignLeft',
},
{
id: `${idPrefix3}1`,
label: 'Align center',
iconType: 'editorAlignCenter',
},
{
id: `${idPrefix3}2`,
label: 'Align right',
iconType: 'editorAlignRight',
isDisabled: true,
},
];

const toggleButtonsIconsMulti = [
{
id: `${idPrefix3}3`,
label: 'Bold',
name: 'bold',
iconType: 'editorBold',
},
{
id: `${idPrefix3}4`,
label: 'Italic',
name: 'italic',
iconType: 'editorItalic',
isDisabled: true,
},
{
id: `${idPrefix3}5`,
label: 'Underline',
name: 'underline',
iconType: 'editorUnderline',
},
{
id: `${idPrefix3}6`,
label: 'Strikethrough',
name: 'strikethrough',
iconType: 'editorStrike',
},
];

const [toggleIconIdSelected, setToggleIconIdSelected] = useState(
`${idPrefix3}1`
);
const [toggleIconIdToSelectedMap, setToggleIconIdToSelectedMap] = useState(
{}
);

const onChangeIcons = (optionId) => {
setToggleIconIdSelected(optionId);
};

const onChangeIconsMulti = (optionId) => {
const newToggleIconIdToSelectedMap = {
...toggleIconIdToSelectedMap,
...{
[optionId]: !toggleIconIdToSelectedMap[optionId],
},
};

setToggleIconIdToSelectedMap(newToggleIconIdToSelectedMap);
};

return (
<Fragment>
<OuiButtonGroup
orientation="vertical"
legend="This is a vertical group"
options={toggleButtons}
idSelected={toggleIdSelected}
onChange={(id) => onChange(id)}
/>
&nbsp;&nbsp;
<OuiButtonGroup
orientation="vertical"
legend="Text align"
options={toggleButtonsIcons}
idSelected={toggleIconIdSelected}
onChange={(id) => onChangeIcons(id)}
isIconOnly
/>
&nbsp;&nbsp;
<OuiButtonGroup
orientation="vertical"
legend="Text style"
options={toggleButtonsIconsMulti}
idToSelectedMap={toggleIconIdToSelectedMap}
onChange={(id) => onChangeIconsMulti(id)}
type="multi"
isIconOnly
/>
<OuiSpacer />
<OuiTitle size="xxs">
<h3>Compressed</h3>
</OuiTitle>
<OuiButtonGroup
buttonSize="compressed"
orientation="vertical"
legend="This is a vertical group"
options={toggleButtons}
idSelected={toggleIdSelected}
onChange={(id) => onChange(id)}
/>
&nbsp;&nbsp;
<OuiButtonGroup
buttonSize="compressed"
orientation="vertical"
legend="Text align"
options={toggleButtonsIcons}
idSelected={toggleIconIdSelected}
onChange={(id) => onChangeIcons(id)}
isIconOnly
/>
&nbsp;&nbsp;
<OuiButtonGroup
buttonSize="compressed"
orientation="vertical"
legend="Text style"
options={toggleButtonsIconsMulti}
idToSelectedMap={toggleIconIdToSelectedMap}
onChange={(id) => onChangeIconsMulti(id)}
type="multi"
isIconOnly
/>
</Fragment>
);
};
Loading
Loading