Skip to content

Commit

Permalink
feat(pill): [DSM-831] add disable state (#815)
Browse files Browse the repository at this point in the history
* feat(pill): [DSM-831] add disable state

* update banner story file

* Bump minor and fix bit eslint issues on pill story

---------

Co-authored-by: Sergio Vanacloig <[email protected]>
  • Loading branch information
acpcor and sergiovanacloig authored Oct 18, 2023
1 parent f375119 commit 8421ba4
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 386 deletions.
8 changes: 4 additions & 4 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"atoms/pill": {
"scope": "carlsberggroup.malty",
"version": "0.0.87",
"version": "0.1.0",
"mainFile": "index.ts",
"rootDir": "malty/atoms/Pill"
},
Expand Down Expand Up @@ -1517,7 +1517,7 @@
},
"molecules/banner": {
"scope": "carlsberggroup.malty",
"version": "0.0.18",
"version": "0.0.19",
"mainFile": "index.ts",
"rootDir": "malty/molecules/Banner"
},
Expand Down Expand Up @@ -1565,7 +1565,7 @@
},
"molecules/product-card": {
"scope": "carlsberggroup.malty",
"version": "0.0.45",
"version": "0.0.46",
"mainFile": "index.ts",
"rootDir": "malty/molecules/ProductCard"
},
Expand Down Expand Up @@ -1613,7 +1613,7 @@
},
"organisms/carousel": {
"scope": "carlsberggroup.malty",
"version": "0.0.28",
"version": "0.0.29",
"mainFile": "index.ts",
"rootDir": "malty/organisms/Carousel"
},
Expand Down
6 changes: 3 additions & 3 deletions malty/atoms/Pill/Pill.helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IconColor } from '@carlsberggroup/malty.atoms.icon-wrapper';
import { globalTheme as defaultTheme } from '@carlsberggroup/malty.theme.malty-theme-provider';
import { useContext } from 'react';
import { ThemeContext } from 'styled-components';
import { IconTextColorProps, PillColor, PillSize, UsePillStylesProps } from './Pill.types';
import { IconTextColorProps, PillSize, PillType, UsePillStylesProps } from './Pill.types';

export const usePillStyles = ({ size }: UsePillStylesProps) => {
const theme = useContext(ThemeContext) || defaultTheme;
Expand Down Expand Up @@ -37,8 +37,8 @@ export const usePillStyles = ({ size }: UsePillStylesProps) => {
return pillStyles[size];
};

export const useIconTextColor = ({ color }: IconTextColorProps) => {
if (color === PillColor.Archive || color === PillColor.Success || color === PillColor.AlertStrong) {
export const useIconTextColor = ({ type }: IconTextColorProps) => {
if (type === PillType.Archive || type === PillType.Success || type === PillType.AlertStrong) {
return IconColor.DigitalBlack;
}

Expand Down
149 changes: 55 additions & 94 deletions malty/atoms/Pill/Pill.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,131 +1,92 @@
import { IconName } from '@carlsberggroup/malty.atoms.icon';
import { Meta, Story } from '@storybook/react';
import { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { Pill as PillComponent } from './Pill';
import { PillColor, PillProps, PillSize } from './Pill.types';
import { Pill } from './Pill';
import { PillProps, PillSize, PillType } from './Pill.types';

export default {
const meta: Meta<PillProps> = {
component: Pill,
title: 'Information/Pill',
component: PillComponent,
parameters: {
importObject: 'Pill',
importPath: '@carlsberggroup/malty.atoms.pill',
variants: ['text', 'icon', 'badge']
importPath: '@carlsberggroup/malty.atoms.pill'
},
render: (args) => <Pill {...args} />,
argTypes: {
text: {
control: 'text',
description: 'Pill content text.'
description: 'Pill content text'
},
size: {
description: 'Pill size, options below.',
description: 'Pill size, options below',
options: Object.values(PillSize),
control: {
type: 'select'
},
table: {
defaultValue: {
summary: 'PillSize.Medium'
}
}
control: 'select'
},
color: {
description: 'Pill colors, from design predefined colors, as follows.',
options: Object.keys(PillColor),
mapping: PillColor,
control: {
type: 'select',
label: Object.values(PillColor)
},
table: {
defaultValue: {
summary: 'PillColor.Closed'
}
}
type: {
description: 'Pill type',
options: Object.keys(PillType),
mapping: PillType,
control: 'select'
},
icon: {
description: 'Icon to be displayed',
options: Object.keys({ undefined, ...IconName }),
mapping: { undefined, ...IconName },
control: {
type: 'select',
label: Object.values({ undefined, ...IconName })
},
table: {
defaultValue: {
summary: 'IconName.CarlsbergFilled'
}
}
control: 'select'
},
badgeMode: {
description: 'Decreases paddings and allows for a circled look as much as possible',
control: 'boolean',
table: { defaultValue: { summary: 'false' } }
control: 'boolean'
},
isUppercase: {
description: 'Use this property to uppercase the text content',
control: 'boolean',
table: { defaultValue: { summary: 'false' } }
control: 'boolean'
},
dataTestId: {
control: 'text',
description: 'Pill data-testid'
}
}
} as Meta;
};

const Template: Story<PillProps> = (args: PillProps) => <PillComponent {...args} />;
type Story = StoryObj<PillProps>;

let PillEl;

const params = new URLSearchParams(window.location.search);
const variant = params.get('variant');

switch (variant) {
case 'icon':
PillEl = Template.bind({});
PillEl.args = {
icon: IconName.CarlsbergFilled,
color: PillColor.Success,
size: PillSize.Medium,
badgeMode: false,
isUppercase: false
};
break;
export const Base: Story = {
args: {
text: 'Text',
icon: IconName.CarlsbergFilled,
type: PillType.Primary,
size: PillSize.Medium,
badgeMode: false,
isUppercase: false
}
};

case 'text':
PillEl = Template.bind({});
PillEl.args = {
text: 'Text',
color: PillColor.Fail,
size: PillSize.Medium,
badgeMode: false,
isUppercase: false
};
break;
export const Icon: Story = {
args: {
...Base.args,
type: PillType.Success,
text: ''
}
};

case 'badge':
PillEl = Template.bind({});
PillEl.args = {
text: '9',
color: PillColor.Success,
size: PillSize.ExtraSmall,
badgeMode: true,
isUppercase: false
};
break;
export const Text: Story = {
args: {
...Base.args,
type: PillType.Fail,
icon: undefined
}
};

default:
PillEl = Template.bind({});
PillEl.args = {
text: 'Text',
icon: IconName.CarlsbergFilled,
color: PillColor.Primary,
size: PillSize.Medium,
badgeMode: false,
isUppercase: false
};
break;
}
export const Badge: Story = {
args: {
...Base.args,
type: PillType.Success,
size: PillSize.ExtraSmall,
icon: undefined,
text: '9',
badgeMode: true
}
};

export const Pill = PillEl;
export default meta;
14 changes: 7 additions & 7 deletions malty/atoms/Pill/Pill.styled.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { IconColor } from '@carlsberggroup/malty.atoms.icon';
import styled, { css } from 'styled-components';
import { PillColor, PillSize } from './Pill.types';
import { PillSize, PillType } from './Pill.types';

export const StyledPill = styled.div<{
size: string;
fontSize: string;
fontFamily: string;
iconSize: string;
padding: string;
color: PillColor;
type: PillType;
textColor: IconColor;
hasText: boolean;
hasIcon: boolean;
Expand All @@ -20,17 +20,17 @@ export const StyledPill = styled.div<{
font-family: ${({ fontFamily }) => `${fontFamily}`};
font-size: ${({ fontSize }) => `${fontSize}`};
font-weight: bold;
background-color: ${({ color, theme }) => {
if (color === PillColor.Primary) {
background-color: ${({ type, theme }) => {
if (type === PillType.Primary) {
return theme.colors.theme.themePrimary.value;
}
if (color === PillColor.Secondary) {
if (type === PillType.Secondary) {
return theme.colors.theme.themeSecondary.value;
}
if (color === PillColor.Archive) {
if (type === PillType.Archive) {
return theme.colors.colours.support[40].value;
}
return theme.colors.colours.system[color].value;
return theme.colors.colours.system[type].value;
}};
color: ${({ textColor }) => textColor};
display: inline-flex;
Expand Down
8 changes: 4 additions & 4 deletions malty/atoms/Pill/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import React, { useContext } from 'react';
import { ThemeContext } from 'styled-components';
import { useIconTextColor, usePillStyles } from './Pill.helper';
import { StyledPill } from './Pill.styled';
import { PillColor, PillProps, PillSize } from './Pill.types';
import { PillProps, PillSize, PillType } from './Pill.types';

export const Pill = ({
text,
icon,
color = PillColor.Primary,
type = PillType.Primary,
size = PillSize.Medium,
badgeMode = false,
isUppercase = false,
dataTestId
}: PillProps) => {
const theme = useContext(ThemeContext) || defaultTheme;
const { fontSize, fontFamily, iconSize, gap, numSize, padding } = usePillStyles({ size });
const colorStyle = useIconTextColor({ color });
const colorStyle = useIconTextColor({ type });
const hasText = !!text;

return (
<StyledPill
data-testid={dataTestId}
color={color}
type={type}
size={numSize}
fontSize={fontSize}
fontFamily={fontFamily}
Expand Down
9 changes: 5 additions & 4 deletions malty/atoms/Pill/Pill.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IconName } from '@carlsberggroup/malty.atoms.icon';
export interface PillProps extends React.HTMLAttributes<HTMLElement> {
text?: string;
icon?: IconName;
color?: PillColor;
type?: PillType;
size?: PillSize;
badgeMode?: boolean;
dataTestId?: string;
Expand All @@ -16,7 +16,7 @@ export enum PillSize {
Medium = 'Medium'
}

export enum PillColor {
export enum PillType {
Primary = 'primary',
Secondary = 'secondary',
Archive = 'support40',
Expand All @@ -26,13 +26,14 @@ export enum PillColor {
NotificationStrong = 'notification-strong',
AlertLight = 'alert-light',
NotificationLight = 'notification-light',
SuccessLight = 'success-light'
SuccessLight = 'success-light',
Disabled = 'disable-light-theme'
}

export interface UsePillStylesProps {
size: PillSize;
}

export interface IconTextColorProps {
color: PillColor;
type: PillType;
}
2 changes: 1 addition & 1 deletion malty/atoms/Pill/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Pill } from './Pill';
export { PillColor, PillSize } from './Pill.types';
export { PillSize, PillType } from './Pill.types';
export type { PillProps } from './Pill.types';
Loading

0 comments on commit 8421ba4

Please sign in to comment.