Unverified Commit 3c974c31 authored by Allison Suarez Miranda's avatar Allison Suarez Miranda Committed by GitHub

feat: clickable badge style behavior (#529)

* looking good, alignment might still be messed up, need to verify

* focused

* more generla styling and added some variables as suggested

* made -height into a variable

* removed unecessary display style

* alpha to variable

* added pressed state styling

* lint fix

* renamed opacity

* added -height

* changed and tested labeltype names

* fixed other labelStyle instances
parent ffea88df
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
@import 'variables'; @import 'variables';
.label-danger { .label-negative {
background-color: $badge-danger-color; background-color: $badge-negative-color;
color: $badge-text-color; color: $badge-text-color;
} }
.label-default { .label-neutral {
background-color: $badge-default-color; background-color: $badge-neutral-color;
color: $badge-text-color; color: $badge-text-color;
} }
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
color: $badge-text-color; color: $badge-text-color;
} }
.label-success { .label-positive {
background-color: $badge-success-color; background-color: $badge-positive-color;
color: $badge-text-color; color: $badge-text-color;
} }
......
...@@ -56,12 +56,20 @@ $line-height-large: 1.5 !default; ...@@ -56,12 +56,20 @@ $line-height-large: 1.5 !default;
// Badges // Badges
$badge-text-color: $text-primary; $badge-text-color: $text-primary;
$badge-danger-color: $sunset20; $badge-negative-color: $sunset20;
$badge-default-color: $gray20; $badge-neutral-color: $gray20;
$badge-primary-color: $cyan10; $badge-primary-color: $cyan10;
$badge-success-color: $mint20; $badge-positive-color: $mint20;
$badge-warning-color: $amber30; $badge-warning-color: $amber30;
$badge-overlay: $gray100;
$badge-opacity-light: 0.14;
$badge-opacity-dark: 0.16;
$badge-pressed-light: 0.21;
$badge-pressed-dark: 0.22;
$badge-height: 20px;
// Buttons // Buttons
$btn-border-radius-base: 4px; $btn-border-radius-base: 4px;
......
...@@ -20,6 +20,7 @@ import { ResourceType } from 'interfaces/Resources'; ...@@ -20,6 +20,7 @@ import { ResourceType } from 'interfaces/Resources';
import * as LogUtils from 'utils/logUtils'; import * as LogUtils from 'utils/logUtils';
import { indexDashboardsEnabled } from 'config/config-utils'; import { indexDashboardsEnabled } from 'config/config-utils';
import { BadgeStyle } from 'config/config-types';
import { AVATAR_SIZE } from './constants'; import { AVATAR_SIZE } from './constants';
import { import {
mapDispatchToProps, mapDispatchToProps,
...@@ -346,7 +347,7 @@ describe('ProfilePage', () => { ...@@ -346,7 +347,7 @@ describe('ProfilePage', () => {
wrapper.find('.header-title-text').find(Flag).props() wrapper.find('.header-title-text').find(Flag).props()
).toMatchObject({ ).toMatchObject({
caseType: 'sentenceCase', caseType: 'sentenceCase',
labelStyle: 'danger', labelStyle: BadgeStyle.DANGER,
text: 'Alumni', text: 'Alumni',
}); });
}); });
......
...@@ -11,6 +11,7 @@ import { bindActionCreators } from 'redux'; ...@@ -11,6 +11,7 @@ import { bindActionCreators } from 'redux';
import Breadcrumb from 'components/common/Breadcrumb'; import Breadcrumb from 'components/common/Breadcrumb';
import Flag from 'components/common/Flag'; import Flag from 'components/common/Flag';
import TabsComponent from 'components/common/TabsComponent'; import TabsComponent from 'components/common/TabsComponent';
import { BadgeStyle } from 'config/config-types';
import { GlobalState } from 'ducks/rootReducer'; import { GlobalState } from 'ducks/rootReducer';
import { getUser, getUserOwn, getUserRead } from 'ducks/user/reducer'; import { getUser, getUserOwn, getUserRead } from 'ducks/user/reducer';
...@@ -215,7 +216,11 @@ export class ProfilePage extends React.Component< ...@@ -215,7 +216,11 @@ export class ProfilePage extends React.Component<
<h1 className="h3 header-title-text truncated"> <h1 className="h3 header-title-text truncated">
{user.display_name} {user.display_name}
{!user.is_active && ( {!user.is_active && (
<Flag caseType="sentenceCase" labelStyle="danger" text="Alumni" /> <Flag
caseType="sentenceCase"
labelStyle={BadgeStyle.DANGER}
text="Alumni"
/>
)} )}
</h1> </h1>
); );
......
...@@ -10,6 +10,7 @@ import { RouteComponentProps } from 'react-router'; ...@@ -10,6 +10,7 @@ import { RouteComponentProps } from 'react-router';
import { GlobalState } from 'ducks/rootReducer'; import { GlobalState } from 'ducks/rootReducer';
import { getTableData } from 'ducks/tableMetadata/reducer'; import { getTableData } from 'ducks/tableMetadata/reducer';
import { GetTableDataRequest } from 'ducks/tableMetadata/types'; import { GetTableDataRequest } from 'ducks/tableMetadata/types';
import { BadgeStyle } from 'config/config-types';
import { import {
getMaxLength, getMaxLength,
...@@ -222,7 +223,7 @@ export class TableDetail extends React.Component< ...@@ -222,7 +223,7 @@ export class TableDetail extends React.Component<
/> />
{data.badges.length > 0 && <BadgeList badges={data.badges} />} {data.badges.length > 0 && <BadgeList badges={data.badges} />}
{data.is_view && ( {data.is_view && (
<Flag text="table view" labelStyle="warning" /> <Flag text="table view" labelStyle={BadgeStyle.WARNING} />
)} )}
</div> </div>
</div> </div>
......
// Copyright Contributors to the Amundsen project. // Copyright Contributors to the Amundsen project.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
@import 'variables'; @import 'variables';
.clickable-badge { .clickable-badge {
&:hover { &:hover {
cursor: pointer; cursor: pointer;
} }
.label {
padding: 0 0;
}
[class^='badge-overlay-'] {
font-size: $font-size-base;
text-align: center;
padding: 0.2em 0.6em 0.3em;
&:hover,
&:focus {
color: $badge-text-color;
height: $badge-height;
width: 100%;
border-radius: $badge-height;
}
&:focus {
// TODO verify if this is what it is supposed to look like
// more round?
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
}
.badge-overlay-negative,
.badge-overlay-neutral,
.badge-overlay-positive,
.badge-overlay-primary {
&:hover,
&:focus {
background-color: rgba(
$color: $badge-overlay,
$alpha: $badge-opacity-light
);
}
&:active {
background-color: rgba(
$color: $badge-overlay,
$alpha: $badge-pressed-light
);
}
}
.badge-overlay-warning {
&:hover,
&:focus {
background-color: rgba(
$color: $badge-overlay,
$alpha: $badge-opacity-dark
);
}
&:active {
background-color: rgba(
$color: $badge-overlay,
$alpha: $badge-pressed-dark
);
}
}
} }
...@@ -6,6 +6,7 @@ import * as React from 'react'; ...@@ -6,6 +6,7 @@ import * as React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import Flag, { CaseType, FlagProps, convertText } from '.'; import Flag, { CaseType, FlagProps, convertText } from '.';
import { BadgeStyle } from 'config/config-types';
describe('Flag', () => { describe('Flag', () => {
let props: FlagProps; let props: FlagProps;
...@@ -21,15 +22,15 @@ describe('Flag', () => { ...@@ -21,15 +22,15 @@ describe('Flag', () => {
describe('render', () => { describe('render', () => {
it('renders span with correct default className', () => { it('renders span with correct default className', () => {
expect(subject.find('span').props().className).toEqual( expect(subject.find('span').props().className).toEqual(
'flag label label-default' `flag label label-${BadgeStyle.DEFAULT}`
); );
}); });
it('renders span with correct custom className', () => { it('renders span with correct custom className', () => {
props.labelStyle = 'primary'; props.labelStyle = BadgeStyle.PRIMARY;
subject.setProps(props); subject.setProps(props);
expect(subject.find('span').props().className).toEqual( expect(subject.find('span').props().className).toEqual(
'flag label label-primary' `flag label label-${BadgeStyle.PRIMARY}`
); );
}); });
......
...@@ -5,6 +5,7 @@ import * as React from 'react'; ...@@ -5,6 +5,7 @@ import * as React from 'react';
// TODO: Use css-modules instead of 'import' // TODO: Use css-modules instead of 'import'
import './styles.scss'; import './styles.scss';
import { BadgeStyle } from 'config/config-types';
export enum CaseType { export enum CaseType {
LOWER_CASE = 'lowerCase', LOWER_CASE = 'lowerCase',
...@@ -41,7 +42,9 @@ const Flag: React.SFC<FlagProps> = ({ ...@@ -41,7 +42,9 @@ const Flag: React.SFC<FlagProps> = ({
// https://getbootstrap.com/docs/4.1/components/badge/ // https://getbootstrap.com/docs/4.1/components/badge/
return ( return (
<span className={`flag label label-${labelStyle}`}> <span className={`flag label label-${labelStyle}`}>
{convertText(text, caseType)} <div className={`badge-overlay-${labelStyle}`}>
{convertText(text, caseType)}
</div>
</span> </span>
); );
}; };
...@@ -49,7 +52,7 @@ const Flag: React.SFC<FlagProps> = ({ ...@@ -49,7 +52,7 @@ const Flag: React.SFC<FlagProps> = ({
Flag.defaultProps = { Flag.defaultProps = {
caseType: null, caseType: null,
text: '', text: '',
labelStyle: 'default', labelStyle: BadgeStyle.DEFAULT,
}; };
export default Flag; export default Flag;
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
.flag { .flag {
border-radius: 5px; border-radius: 5px;
display: inline-block; display: inline-block;
font-size: 14px; font-size: $font-size-base;
height: 20px; height: $badge-height;
margin: 0 0 0 $spacer-1; margin: 0 0 0 $spacer-1;
} }
......
...@@ -12,6 +12,8 @@ import { Link } from 'react-router-dom'; ...@@ -12,6 +12,8 @@ import { Link } from 'react-router-dom';
import { ResourceType } from 'interfaces'; import { ResourceType } from 'interfaces';
import UserListItem, { UserListItemProps } from '.'; import UserListItem, { UserListItemProps } from '.';
import { BadgeStyle } from 'config/config-types';
describe('UserListItem', () => { describe('UserListItem', () => {
const setup = (propOverrides?: Partial<UserListItemProps>) => { const setup = (propOverrides?: Partial<UserListItemProps>) => {
const props: UserListItemProps = { const props: UserListItemProps = {
...@@ -209,7 +211,7 @@ describe('UserListItem', () => { ...@@ -209,7 +211,7 @@ describe('UserListItem', () => {
expect(flagComponent.exists()).toBe(true); expect(flagComponent.exists()).toBe(true);
expect(flagComponent.props()).toMatchObject({ expect(flagComponent.props()).toMatchObject({
text: 'Alumni', text: 'Alumni',
labelStyle: 'danger', labelStyle: BadgeStyle.DANGER,
}); });
}); });
......
...@@ -7,6 +7,7 @@ import { Link } from 'react-router-dom'; ...@@ -7,6 +7,7 @@ import { Link } from 'react-router-dom';
import { UserResource } from 'interfaces'; import { UserResource } from 'interfaces';
import Flag from 'components/common/Flag'; import Flag from 'components/common/Flag';
import { BadgeStyle } from 'config/config-types';
import { LoggingParams } from '../types'; import { LoggingParams } from '../types';
export interface UserListItemProps { export interface UserListItemProps {
...@@ -55,7 +56,9 @@ class UserListItem extends React.Component<UserListItemProps, {}> { ...@@ -55,7 +56,9 @@ class UserListItem extends React.Component<UserListItemProps, {}> {
</div> </div>
<div className="resource-type">User</div> <div className="resource-type">User</div>
<div className="resource-badges"> <div className="resource-badges">
{!user.is_active && <Flag text="Alumni" labelStyle="danger" />} {!user.is_active && (
<Flag text="Alumni" labelStyle={BadgeStyle.DANGER} />
)}
<img className="icon icon-right" alt="" /> <img className="icon icon-right" alt="" />
</div> </div>
</Link> </Link>
......
...@@ -134,11 +134,11 @@ interface BaseResourceConfig { ...@@ -134,11 +134,11 @@ interface BaseResourceConfig {
} }
export enum BadgeStyle { export enum BadgeStyle {
DANGER = 'danger', DANGER = 'negative',
DEFAULT = 'default', DEFAULT = 'neutral',
INFO = 'info', INFO = 'info',
PRIMARY = 'primary', PRIMARY = 'primary',
SUCCESS = 'success', SUCCESS = 'positive',
WARNING = 'warning', WARNING = 'warning',
} }
......
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