@dtdot/lego 0.17.17 → 0.17.21

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
+ };
@@ -1,3 +1,4 @@
1
+ export declare const getValue: <T = string>(value: T, contextValue: T) => T;
1
2
  declare function useFormNode<T = string, K = string>(key?: string): {
2
3
  value: undefined;
3
4
  error: undefined;
@@ -1,5 +1,11 @@
1
1
  import { useContext } from 'react';
2
2
  import FormStateContext from './FormState.context';
3
+ export const getValue = (value, contextValue) => {
4
+ if (value !== null && value !== undefined) {
5
+ return value;
6
+ }
7
+ return contextValue;
8
+ };
3
9
  function useFormNode(key) {
4
10
  const { value, errors, onChange } = useContext(FormStateContext);
5
11
  if (!key) {
@@ -5,7 +5,7 @@ import { motion } from 'framer-motion';
5
5
  import React, { useState } from 'react';
6
6
  import styled, { css } from 'styled-components';
7
7
  import getThemeControlColours from '../../theme/helpers/getThemeControlColours';
8
- import useFormNode from '../Form/useFormNode.hook';
8
+ import useFormNode, { getValue } from '../Form/useFormNode.hook';
9
9
  export const INPUT_HEIGHT = 48;
10
10
  const InputContainer = styled(motion.div) `
11
11
  position: relative;
@@ -120,7 +120,7 @@ const Input = React.forwardRef(function ForwardRefInput(props, ref) {
120
120
  return (React.createElement("div", null,
121
121
  label && React.createElement(InputLabel, { htmlFor: name }, label),
122
122
  React.createElement(InputContainer, { animate: error ? (isFocused ? 'errorFocus' : 'error') : undefined },
123
- React.createElement(StyledInput, { ref: ref, variants: inputVariants, transition: { type: 'spring', duration: 0.3 }, type: type, name: name, placeholder: placeholder, value: value || contextValue, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur }),
123
+ React.createElement(StyledInput, { ref: ref, variants: inputVariants, transition: { type: 'spring', duration: 0.3 }, type: type, name: name, placeholder: placeholder, value: getValue(value, contextValue), onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur }),
124
124
  React.createElement(ErrorContainer, { animate: error ? 'show' : undefined, style: { opacity: 0 }, variants: errorVariants, transition: { type: 'spring', duration: 0.3 } },
125
125
  React.createElement(ErrorInner, null,
126
126
  React.createElement(FontAwesomeIcon, { icon: faExclamationCircle }))),
@@ -12,6 +12,6 @@ declare const Table: {
12
12
  ({ children, variant }: TableProps): JSX.Element;
13
13
  Row: ({ children }: import("./_TableRow.component").TableRowProps) => JSX.Element;
14
14
  Cell: import("styled-components").StyledComponent<"td", import("styled-components").DefaultTheme, TableCellProps, never>;
15
- Action: ({ text }: import("./_TableAction").TableActionProps) => JSX.Element;
15
+ Action: ({ text, onClick }: import("./_TableAction").TableActionProps) => JSX.Element;
16
16
  };
17
17
  export default Table;
@@ -20,7 +20,8 @@ const TableCell = styled.td `
20
20
  const Table = ({ children, variant = 'regular' }) => {
21
21
  return (React.createElement(TableContext.Provider, { value: { variant } },
22
22
  React.createElement(ButtonContext.Provider, { value: { height: '24px' } },
23
- React.createElement(StyledTable, null, children))));
23
+ React.createElement(StyledTable, null,
24
+ React.createElement("tbody", null, children)))));
24
25
  };
25
26
  Table.Row = TableRow;
26
27
  Table.Cell = TableCell;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Card, ProfileImage, Table } from '../..';
3
+ /* eslint-disable @typescript-eslint/no-empty-function */
3
4
  const fakeData = [
4
5
  {
5
6
  count: 57,
@@ -45,7 +46,7 @@ export const WithActions = () => (React.createElement(Table, null, fakeData.map(
45
46
  React.createElement(Table.Cell, null, data.count),
46
47
  React.createElement(Table.Cell, null, data.name),
47
48
  React.createElement(Table.Cell, null,
48
- React.createElement(Table.Action, { text: 'filter' })))))));
49
+ React.createElement(Table.Action, { onClick: () => { }, text: 'filter' })))))));
49
50
  export const InCard = () => (React.createElement(Card, { padded: true, size: 'sm' },
50
51
  React.createElement(Table, null,
51
52
  React.createElement(Table.Row, null,
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  export interface TableActionProps {
3
3
  text: string;
4
+ onClick: () => void;
4
5
  }
5
- declare const TableAction: ({ text }: TableActionProps) => JSX.Element;
6
+ declare const TableAction: ({ text, onClick }: TableActionProps) => JSX.Element;
6
7
  export default TableAction;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import Button from '../Button/Button.component';
3
- const TableAction = ({ text }) => {
4
- return React.createElement(Button, { variant: 'tertiary' }, text);
3
+ const TableAction = ({ text, onClick }) => {
4
+ return (React.createElement(Button, { variant: 'tertiary', onClick: onClick }, text));
5
5
  };
6
6
  export default TableAction;
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.17",
3
+ "version": "0.17.21",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {