Skip to content

Commit

Permalink
More Label touchups (margins) (#10722)
Browse files Browse the repository at this point in the history
* labels with onClick don't need .pointer. No labels need `m-r-5`

* making Timer a proper Label

* a little linting

* addresing (helpful, thanks) comment
  • Loading branch information
rusackas authored and villebro committed Sep 11, 2020
1 parent 5fbe751 commit d410b8b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/components/LimitControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class LimitControl extends React.PureComponent<
render() {
return (
<div>
<Label className="pointer" onClick={this.handleToggle}>
<Label onClick={this.handleToggle}>
LIMIT {this.props.value || this.props.maxRow}
</Label>
<Overlay
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/CachedLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CacheLabel extends React.PureComponent {
return (
<TooltipWrapper tooltip={this.state.tooltipContent} label="cache-desc">
<Label
className={`${this.props.className} m-r-5 pointer`}
className={`${this.props.className}`}
bsStyle={labelStyle}
onClick={this.props.onClick}
onMouseOver={this.mouseOver.bind(this)}
Expand Down
7 changes: 1 addition & 6 deletions superset-frontend/src/components/Label/Label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ export const bsStyleKnob = {
export const LabelGallery = () => (
<>
{Object.values(bsStyleKnob.options).map(opt => (
<Label
key={opt}
bsStyle={opt}
style={{ marginRight: '10px' }}
onClick={action('clicked')}
>
<Label key={opt} bsStyle={opt} onClick={action('clicked')}>
{`style: "${opt}"`}
</Label>
))}
Expand Down
19 changes: 16 additions & 3 deletions superset-frontend/src/components/Label/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import React from 'react';
import { Label as BootstrapLabel } from 'react-bootstrap';
import styled from '@superset-ui/style';
import cx from 'classnames';

export type OnClickHandler = React.MouseEventHandler<BootstrapLabel>;

export interface LabelProps {
key?: string;
className?: string;
id?: string;
tooltip?: string;
placement?: string;
onClick?: OnClickHandler;
Expand All @@ -34,6 +36,15 @@ export interface LabelProps {
}

const SupersetLabel = styled(BootstrapLabel)`
/* un-bunch them! */
margin-right: ${({ theme }) => theme.gridUnit}px;
&:first-of-type {
margin-left: 0;
}
&:last-of-type {
margin-right: 0;
}
cursor: ${({ onClick }) => (onClick ? 'pointer' : 'default')};
transition: background-color ${({ theme }) => theme.transitionTiming}s;
&.label-warning {
Expand Down Expand Up @@ -103,9 +114,11 @@ export default function Label(props: LabelProps) {
bsStyle: officialBootstrapStyles.includes(props.bsStyle || '')
? props.bsStyle
: 'default',
className: officialBootstrapStyles.includes(props.bsStyle || '')
? undefined
: `label-${props.bsStyle}`,
className: cx(props.className, {
[`label-${props.bsStyle}`]: !officialBootstrapStyles.includes(
props.bsStyle || '',
),
}),
};
return <SupersetLabel {...labelProps}>{props.children}</SupersetLabel>;
}
4 changes: 1 addition & 3 deletions superset-frontend/src/components/TableSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ export default class TableSelector extends React.PureComponent {
renderDatabaseOption(db) {
return (
<span title={db.database_name}>
<Label bsStyle="default" className="m-r-5">
{db.backend}
</Label>
<Label bsStyle="default">{db.backend}</Label>
{db.database_name}
</span>
);
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/components/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useEffect, useState } from 'react';
import { Label } from 'react-bootstrap';
import Label from 'src/components/Label';

import { now, fDuration } from '../modules/dates';

Expand Down Expand Up @@ -73,7 +73,7 @@ export default function Timer({
});

return (
<Label id="timer" className="m-r-5" bsStyle={status}>
<Label id="timer" bsStyle={status}>
{clockStr}
</Label>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const StyledHeader = styled.div`
align-items: center;
justify-content: flex-end;
.btn-group {
> .btn-group {
flex: 0 0 auto;
margin-left: ${({ theme }) => theme.gridUnit}px;
}
}
`;
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/explore/components/RowCountLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function RowCountLabel({ rowcount, limit, suffix }) {
);
return (
<TooltipWrapper label="tt-rowcount" tooltip={tooltip}>
<Label bsStyle={bsStyle} className="m-r-5 pointer">
<Label bsStyle={bsStyle}>
{formattedRowCount} {suffix}
</Label>
</TooltipWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class FixedOrMetricControl extends React.Component {
return (
<div>
<ControlHeader {...this.props} />
<Label className="pointer" onClick={this.toggle}>
<Label onClick={this.toggle}>
{this.state.type === controlTypes.fixed && (
<span>{this.state.fixedValue}</span>
)}
Expand Down

0 comments on commit d410b8b

Please sign in to comment.