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

style: Label styling/storybook touchups #10627

Merged
merged 11 commits into from
Aug 18, 2020
82 changes: 56 additions & 26 deletions superset-frontend/src/components/Label/index.tsx
Original file line number Diff line number Diff line change
@@ -34,48 +34,78 @@ export interface LabelProps {
}

const SupersetLabel = styled(BootstrapLabel)`
&.supersetLabel {
border-radius: ${({ theme }) => theme.borderRadius}px;
border: none;
color: ${({ theme }) => theme.colors.secondary.light5};
font-size: ${({ theme }) => theme.typography.sizes.s};
font-weight: ${({ theme }) => theme.typography.weights.bold};
min-width: ${({ theme }) => theme.gridUnit * 36}px;
min-height: ${({ theme }) => theme.gridUnit * 8}px;
text-transform: uppercase;
margin-left: ${({ theme }) => theme.gridUnit * 4}px;
&:first-of-type {
margin-left: 0;
cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')};
transition: background-color ${({ theme }) => theme.transitionTiming}s;
&.label-warning {
background-color: ${({ theme }) => theme.colors.warning.base};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.warning.dark1 : theme.colors.warning.base};
}
i {
padding: 0 ${({ theme }) => theme.gridUnit * 2}px 0 0;
}
&.label-danger {
background-color: ${({ theme }) => theme.colors.error.base};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.error.dark1 : theme.colors.error.base};
}
&.primary {
background-color: ${({ theme }) => theme.colors.primary.base};
}
&.label-success {
background-color: ${({ theme }) => theme.colors.success.base};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.success.dark1 : theme.colors.success.base};
}
&.secondary {
color: ${({ theme }) => theme.colors.primary.base};
background-color: ${({ theme }) => theme.colors.primary.light4};
}
&.label-default {
background-color: ${({ theme }) => theme.colors.grayscale.base};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.grayscale.dark1 : theme.colors.grayscale.base};
}
&.danger {
background-color: ${({ theme }) => theme.colors.error.base};
}
&.label-info {
background-color: ${({ theme }) => theme.colors.info};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.info.dark1 : theme.colors.info.base};
}
}
&.secondaryLabel {
&.label-primary {
background-color: ${({ theme }) => theme.colors.primary.base};
&:hover {
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.primary.dark1 : theme.colors.primary.base};
}
}
/* note this is NOT a supported bootstrap label Style... this overrides default */
&.label-secondary {
background-color: ${({ theme }) => theme.colors.secondary.base};
&:hover {
background-color: ${({ theme }) => theme.colors.secondary.base};
background-color: ${({ theme, onClick }) =>
onClick ? theme.colors.secondary.dark1 : theme.colors.secondary.base};
}
}
`;

export default function Label(props: LabelProps) {
const officialBootstrapStyles = [
'success',
'warning',
'danger',
'info',
'default',
'primary',
];
const labelProps = {
...props,
placement: props.placement || 'top',
bsStyle: officialBootstrapStyles.includes(props.bsStyle || '')
? props.bsStyle
: 'default',
className: officialBootstrapStyles.includes(props.bsStyle || '')
? undefined
: `label-${props.bsStyle}`,
};
return <SupersetLabel {...labelProps}>{props.children}</SupersetLabel>;
}
42 changes: 25 additions & 17 deletions superset-frontend/src/components/Label/label.stories.jsx
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
*/
import React from 'react';
import { action } from '@storybook/addon-actions';
import { withKnobs, select, text } from '@storybook/addon-knobs';
import { withKnobs, select, boolean, text } from '@storybook/addon-knobs';
import Label from './index';

export default {
@@ -30,36 +30,44 @@ export default {
const bsStyleKnob = {
label: 'Types',
options: {
danger: 'danger',
warning: 'warning',
success: 'success',
default: 'default',
info: 'info',
success: 'success',
warning: 'warning',
danger: 'danger',
secondary: 'secondary',
primary: 'primary',
},
defaultValue: 'default',
};
export const SupersetLabel = () => (

export const LabelGallery = () => (
<div style={{ padding: '10px' }}>
{Object.values(bsStyleKnob.options).map(opt => (
<Label
key={opt}
bsStyle={opt}
style={{ marginRight: '10px' }}
onClick={action('clicked')}
>
{`style: "${opt}"`}
</Label>
))}
</div>
);

export const InteractiveLabel = () => (
<div style={{ padding: '10px' }}>
<h2>Interactive</h2>
<Label
bsStyle={select(
bsStyleKnob.label,
bsStyleKnob.options,
bsStyleKnob.defaultValue,
bsStyleKnob.groupId,
)}
onClick={action('clicked')}
onClick={boolean('Has onClick action', false) ? action('clicked') : false}
>
{text('Label', 'Label!')}
</Label>
<h2>Gallery</h2>
{Object.values(bsStyleKnob.options).map(opt => (
<Label
bsStyle={opt}
style={{ marginRight: '10px' }}
onClick={action('clicked')}
>
{`style: "${opt}"`}
</Label>
))}
</div>
);
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
@@ -540,7 +540,7 @@ class ChartList extends React.PureComponent<Props, State> {
/>
))}
coverRight={
<Label className="secondaryLabel">{props.datasource_name_text}</Label>
<Label bsStyle="secondary">{props.datasource_name_text}</Label>
}
actions={
<ListViewCard.Actions>