@dtdot/lego 0.17.19 → 0.17.22
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.
- package/build/components/Badge/Badge.component.d.ts +4 -0
- package/build/components/Badge/Badge.component.js +1 -1
- package/build/components/BadgeSelector/BadgeSelector.component.d.ts +14 -0
- package/build/components/BadgeSelector/BadgeSelector.component.js +25 -0
- package/build/components/BadgeSelector/BadgeSelector.stories.d.ts +5 -0
- package/build/components/BadgeSelector/BadgeSelector.stories.js +33 -0
- package/build/components/Form/useFormNode.hook.d.ts +1 -0
- package/build/components/Form/useFormNode.hook.js +6 -0
- package/build/components/Input/Input.component.d.ts +1 -0
- package/build/components/Input/Input.component.js +3 -3
- package/build/components/Table/Table.component.js +2 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +1 -1
|
@@ -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,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,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;
|
|
@@ -93,7 +93,7 @@ const messageVariants = {
|
|
|
93
93
|
errorFocus: { opacity: 1, y: -4 },
|
|
94
94
|
};
|
|
95
95
|
const Input = React.forwardRef(function ForwardRefInput(props, ref) {
|
|
96
|
-
const { label, name, placeholder, type = 'text', value, error: propsError, onChange, onFocus, onBlur } = props;
|
|
96
|
+
const { label, name, placeholder, type = 'text', autoFocus, value, error: propsError, onChange, onFocus, onBlur, } = props;
|
|
97
97
|
const [isFocused, setIsFocused] = useState(false);
|
|
98
98
|
const { value: contextValue, error: contextError, onChange: contextOnChange } = useFormNode(name);
|
|
99
99
|
const error = contextError || propsError;
|
|
@@ -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
|
|
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, autoFocus: autoFocus }),
|
|
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 }))),
|
|
@@ -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,
|
|
23
|
+
React.createElement(StyledTable, null,
|
|
24
|
+
React.createElement("tbody", null, children)))));
|
|
24
25
|
};
|
|
25
26
|
Table.Row = TableRow;
|
|
26
27
|
Table.Cell = TableCell;
|
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';
|