@dtdot/lego 0.17.19 → 0.17.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,9 @@
1
1
  import React from 'react';
2
2
  import { Status } from '../../theme/theme.types';
3
+ interface BadgeSpanProps {
4
+ variant: BadgeVariant;
5
+ }
6
+ export declare const BadgeSpan: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, BadgeSpanProps, never>;
3
7
  export declare type BadgeVariant = Status;
4
8
  export interface BadgeProps {
5
9
  children: React.ReactNode;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
3
  import getThemeStatusColour from '../../theme/helpers/getThemeStatusColour';
4
- const BadgeSpan = styled.span `
4
+ export const BadgeSpan = styled.span `
5
5
  padding: 4px 8px;
6
6
  border-radius: 2px;
7
7
 
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { BadgeVariant } from '../Badge/Badge.component';
3
+ export interface BadgeSelectorOption {
4
+ value: string;
5
+ name: string;
6
+ variant: BadgeVariant;
7
+ }
8
+ export interface BadgeSelectorProps {
9
+ options: BadgeSelectorOption[];
10
+ value: string[];
11
+ onChange: (val: string[]) => void;
12
+ }
13
+ declare const BadgeSelector: ({ options, value, onChange }: BadgeSelectorProps) => JSX.Element;
14
+ export default BadgeSelector;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import getThemeVariantColours from '../../theme/helpers/getThemeVariantColours';
4
+ import { BadgeSpan } from '../Badge/Badge.component';
5
+ const InteractiveBadge = styled(BadgeSpan) `
6
+ cursor: pointer;
7
+
8
+ ${(props) => props.inactive &&
9
+ `
10
+ background-color: ${getThemeVariantColours('tertiary', props.theme).main};
11
+ color: ${getThemeVariantColours('tertiary', props.theme).contrastText};
12
+ `}
13
+ `;
14
+ const BadgeSelectorOuter = styled.div `
15
+ ${InteractiveBadge} {
16
+ margin-right: 8px;
17
+ }
18
+ `;
19
+ const BadgeSelector = ({ options, value, onChange }) => {
20
+ const handleClick = (_value) => {
21
+ onChange([_value]);
22
+ };
23
+ return (React.createElement(BadgeSelectorOuter, null, options.map((option) => (React.createElement(InteractiveBadge, { key: option.value, variant: option.variant, inactive: !value.includes(option.value), onClick: () => handleClick(option.value) }, option.name)))));
24
+ };
25
+ export default BadgeSelector;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { Meta } from '@storybook/react/types-6-0';
3
+ export declare const Standard: () => JSX.Element;
4
+ declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
5
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import React, { useState } from 'react';
2
+ import { BadgeSelector } from '../..';
3
+ /* eslint-disable @typescript-eslint/no-empty-function */
4
+ const options = [
5
+ {
6
+ value: 'pending',
7
+ name: 'Pending',
8
+ variant: 'info',
9
+ },
10
+ {
11
+ value: 'accepted',
12
+ name: 'Accepted',
13
+ variant: 'success',
14
+ },
15
+ {
16
+ value: 'expired',
17
+ name: 'Expired',
18
+ variant: 'warn',
19
+ },
20
+ {
21
+ value: 'rejected',
22
+ name: 'Rejected',
23
+ variant: 'danger',
24
+ },
25
+ ];
26
+ export const Standard = () => {
27
+ const [value, setValue] = useState(['pending']);
28
+ return React.createElement(BadgeSelector, { options: options, value: value, onChange: setValue });
29
+ };
30
+ export default {
31
+ title: 'Components/BadgeSelector',
32
+ component: BadgeSelector,
33
+ };
package/build/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { default as BodyStyle } from './global/BodyStyle.component';
2
2
  export { default as ActionMessage } from './components/ActionMessage/ActionMessage.component';
3
3
  export { default as Alert } from './components/Alert/Alert.component';
4
4
  export { default as Badge } from './components/Badge/Badge.component';
5
+ export { default as BadgeSelector } from './components/BadgeSelector/BadgeSelector.component';
5
6
  export { default as Button } from './components/Button/Button.component';
6
7
  export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
7
8
  export { default as Card } from './components/Card/Card.component';
package/build/index.js CHANGED
@@ -2,6 +2,7 @@ export { default as BodyStyle } from './global/BodyStyle.component';
2
2
  export { default as ActionMessage } from './components/ActionMessage/ActionMessage.component';
3
3
  export { default as Alert } from './components/Alert/Alert.component';
4
4
  export { default as Badge } from './components/Badge/Badge.component';
5
+ export { default as BadgeSelector } from './components/BadgeSelector/BadgeSelector.component';
5
6
  export { default as Button } from './components/Button/Button.component';
6
7
  export { default as ButtonGroup } from './components/ButtonGroup/ButtonGroup.component';
7
8
  export { default as Card } from './components/Card/Card.component';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "0.17.19",
3
+ "version": "0.17.20",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {