Commit dc0bfb26 by Peter Holmberg Committed by GitHub

Fix: Align buttons and label in ToggleButtonGroup (#19036)

parent e4e77194
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { ToggleButton, ToggleButtonGroup } from './ToggleButtonGroup';
import { UseState } from '../../utils/storybook/UseState';
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
const ToggleButtonGroupStories = storiesOf('UI/ToggleButtonGroup', module);
const options = [
{ value: 'first', label: 'First' },
{ value: 'second', label: 'Second' },
{ value: 'third', label: 'Third' },
];
ToggleButtonGroupStories.addDecorator(withCenteredStory);
ToggleButtonGroupStories.add('default', () => {
return (
<UseState
initialState={{
value: 'first',
}}
>
{(value, updateValue) => {
return (
<ToggleButtonGroup label="Options">
{options.map((option, index) => {
return (
<ToggleButton
key={`${option.value}-${index}`}
value={option.value}
onChange={newValue => {
action('on change')(newValue);
updateValue({ value: newValue });
}}
selected={value.value === option.value}
>
{option.label}
</ToggleButton>
);
})}
</ToggleButtonGroup>
);
}}
</UseState>
);
});
......@@ -12,7 +12,7 @@ export class ToggleButtonGroup extends PureComponent<ToggleButtonGroupProps> {
const { children, label, transparent } = this.props;
return (
<div className="gf-form">
<div className="gf-form gf-form--align-center">
{label && <label className={`gf-form-label ${transparent ? 'gf-form-label--transparent' : ''}`}>{label}</label>}
<div className={`toggle-button-group ${transparent ? 'toggle-button-group--transparent' : ''}`}>{children}</div>
</div>
......@@ -44,7 +44,7 @@ export const ToggleButton: FC<ToggleButtonProps> = ({
}
};
const btnClassName = `btn ${className} ${selected ? 'active' : ''}`;
const btnClassName = `btn ${className}${selected ? ' active' : ''}`;
const button = (
<button className={btnClassName} onClick={onClick}>
<span>{children}</span>
......
......@@ -20,6 +20,10 @@ $input-border: 1px solid $input-border-color;
justify-content: flex-end;
}
&--align-center {
align-content: center;
}
&--alt {
flex-direction: column;
align-items: flex-start;
......
.toggle-button-group {
display: flex;
padding-top: 5px;
.btn {
@include buttonBackground($btn-inverse-bg, $btn-inverse-bg-hl, $btn-inverse-text-color, $btn-inverse-text-shadow);
height: $input-height;
padding: 7px 10px;
font-weight: $font-weight-semi-bold;
font-size: $font-size-sm;
......
......@@ -349,10 +349,6 @@
.query-type-toggle {
margin-left: 5px;
.toggle-button-group {
padding-top: 2px;
}
.btn.active {
background-color: $input-bg;
background-image: none;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment