diff --git a/src/components/Dropdown/Dropdown.stories.jsx b/src/components/Dropdown/Dropdown.stories.jsx index f32f4cff..03479003 100644 --- a/src/components/Dropdown/Dropdown.stories.jsx +++ b/src/components/Dropdown/Dropdown.stories.jsx @@ -3,6 +3,7 @@ import {action} from '@storybook/addon-actions'; import markdownNotes from './Dropdown.md'; import {Dropdown} from './index'; import {Love} from '~/icons'; +import {Pill, Typography} from '~/components'; import { dropdownData, dropdownDataDescriptions, @@ -369,3 +370,49 @@ export const DropdownWithTreeMultiple = () => { ); }; +export const DropdownWithPill = () => { + const [currentOption, setCurrentOption] = useState([]); + + const dataLanguages = [ + { + label: 'French', + value: 'fr', + iconEnd: + }, + { + label: <>French (Canadian), + value: 'fr_ca', + iconEnd: + }, + { + label: <>Language with very long long label label label label label label label name (country name), + value: 'es', + iconEnd: + }, + { + label: 'English', + value: 'en', + iconEnd: + } + ]; + + const handleOnChange = (e, item) => { + setCurrentOption(item); + action('onChange'); + return true; + }; + + return ( + 0 ? : null} + label={currentOption.label} + placeholder="Select something" + value={currentOption.value} + size="small" + isDisabled={false} + data={dataLanguages} + onChange={(e, item) => handleOnChange(e, item)} + /> + ); +}; diff --git a/src/components/ListItem/ListItem.scss b/src/components/ListItem/ListItem.scss index 3e1ed881..f7eeca29 100644 --- a/src/components/ListItem/ListItem.scss +++ b/src/components/ListItem/ListItem.scss @@ -39,7 +39,7 @@ $big-image-size: 96px; .moonstone-listItem_iconEnd { display: flex; align-items: center; - width: 16px; + min-width: 16px; height: 16px; } diff --git a/src/components/ListSelector/ValueList/ValueList.scss b/src/components/ListSelector/ValueList/ValueList.scss index 8812fd23..250d7615 100644 --- a/src/components/ListSelector/ValueList/ValueList.scss +++ b/src/components/ListSelector/ValueList/ValueList.scss @@ -5,8 +5,6 @@ } .moonstone-iconContainer { - min-width: var(--spacing-large); - .moonstone-displayNone { display: none; } diff --git a/src/components/Pill/Pill.md b/src/components/Pill/Pill.md new file mode 100644 index 00000000..f4877931 --- /dev/null +++ b/src/components/Pill/Pill.md @@ -0,0 +1,4 @@ +The `Pill` component is a very simple variation of the `Chip` component. + +### Usages +The `Pill` component must be used in a dropdownMenu to add information (eg: Add the code language in a language switcher) diff --git a/src/components/Pill/Pill.scss b/src/components/Pill/Pill.scss new file mode 100644 index 00000000..9bfece2c --- /dev/null +++ b/src/components/Pill/Pill.scss @@ -0,0 +1,11 @@ +// empty +.moonstone-pill { + padding: 0 var(--spacing-nano); + + border-radius: 2px; + background-color: var(--color-gray_light40); + + &.moonstone-pill_reversed { + color: var(--color-light); + } +} diff --git a/src/components/Pill/Pill.spec.js b/src/components/Pill/Pill.spec.js new file mode 100644 index 00000000..3a4757c4 --- /dev/null +++ b/src/components/Pill/Pill.spec.js @@ -0,0 +1,21 @@ +import React from 'react'; +import {render, screen} from '@testing-library/react'; +import {Pill} from './index'; + +describe('Pill', () => { + it('should display label', () => { + render(); + expect(screen.getByText('Say my name')).toBeInTheDocument(); + }); + + it('should add additional class names', () => { + const testClassName = 'hello'; + render(); + expect(screen.getByTestId('moonstone-listItemChip')).toHaveClass(testClassName); + }); + + it('should add additional attribute', () => { + render(); + expect(screen.getByTestId('moonstone-listItemChip')).toBeInTheDocument(); + }); +}); diff --git a/src/components/Pill/Pill.stories.tsx b/src/components/Pill/Pill.stories.tsx new file mode 100644 index 00000000..100c7b60 --- /dev/null +++ b/src/components/Pill/Pill.stories.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import {Story} from '@storybook/react'; +import markdownNotes from './Pill.md'; + +import {Pill} from './index'; +import type {PillProps} from './Pill.types'; + +export default { + title: 'Components/Pill', + component: Pill, + + parameters: { + layout: 'centered', + notes: {markdown: markdownNotes} + } +}; + +export const Default: Story = args => ( + +); +Default.args = { + label: 'ListItem label' +}; diff --git a/src/components/Pill/Pill.tsx b/src/components/Pill/Pill.tsx new file mode 100644 index 00000000..ffd9f8a7 --- /dev/null +++ b/src/components/Pill/Pill.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import clsx from 'clsx'; + +import type {PillProps} from './Pill.types'; + +import {Typography} from '~/components/Typography'; +import './Pill.scss'; + +export const Pill: React.FC = ({ + label, + className, + isReversed, + ...props +}) => { + return ( + + {label} + + ); +}; + +Pill.displayName = 'Pill'; diff --git a/src/components/Pill/Pill.types.ts b/src/components/Pill/Pill.types.ts new file mode 100644 index 00000000..540b450d --- /dev/null +++ b/src/components/Pill/Pill.types.ts @@ -0,0 +1,16 @@ +export type PillProps = { + /** + * ListItem label + */ + label: string; + + /** + * Reversed style for dark background with light text + */ + isReversed?: boolean; + + /** + * Additional classname + */ + className?: string; +} diff --git a/src/components/Pill/index.ts b/src/components/Pill/index.ts new file mode 100644 index 00000000..c32b0856 --- /dev/null +++ b/src/components/Pill/index.ts @@ -0,0 +1 @@ +export * from './Pill'; diff --git a/src/components/index.ts b/src/components/index.ts index 3db26805..4e6db3a4 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -19,6 +19,7 @@ export * from './ListSelector'; export * from './Loader'; export * from './Menu'; export * from './Paper'; +export * from './Pill'; export * from './PrimaryNav'; export * from './PrimaryNav/PrimaryNavItem'; export * from './PrimaryNav/PrimaryNavItemsGroup';