@dtdot/lego 0.17.9 → 0.17.10
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/InlineCard/InlineCard.component.d.ts +2 -1
- package/build/components/InlineCard/InlineCard.component.js +47 -3
- package/build/components/InlineCard/InlineCard.stories.d.ts +1 -0
- package/build/components/InlineCard/InlineCard.stories.js +25 -3
- package/build/components/InlineCard/InlineCardSelection.component.d.ts +9 -0
- package/build/components/InlineCard/InlineCardSelection.component.js +28 -0
- package/build/components/InlineCard/_InlineCardSelection.context.d.ts +8 -0
- package/build/components/InlineCard/_InlineCardSelection.context.js +6 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +1 -1
|
@@ -6,12 +6,13 @@ export declare type DragVariant = Status;
|
|
|
6
6
|
export interface InlineCardProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
size?: InlineCardSize;
|
|
9
|
+
value?: string;
|
|
9
10
|
gestureLeftIcon?: IconProp;
|
|
10
11
|
gestureLeftVariant?: DragVariant;
|
|
11
12
|
onGestureLeft?: () => void;
|
|
12
13
|
}
|
|
13
14
|
declare const InlineCard: {
|
|
14
|
-
({ children, size, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }: InlineCardProps): JSX.Element;
|
|
15
|
+
({ children, size, value, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }: InlineCardProps): JSX.Element;
|
|
15
16
|
Media: ({ children }: import("./_InlineCardMedia.component").InlineCardMediaProps) => JSX.Element;
|
|
16
17
|
Content: ({ children, center }: import("./_InlineCardContent.component").InlineCardContentProps) => JSX.Element;
|
|
17
18
|
Meta: ({ children }: import("./_InlineCardMeta.component").InlineCardMetaProps) => JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { motion, useMotionValue, useTransform } from 'framer-motion';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useContext, useState } from 'react';
|
|
3
3
|
import styled, { useTheme } from 'styled-components';
|
|
4
4
|
import useMeasure from 'react-use-measure';
|
|
5
5
|
import { responsive } from '../..';
|
|
@@ -8,6 +8,8 @@ import InlineCardContent from './_InlineCardContent.component';
|
|
|
8
8
|
import InlineCardMedia from './_InlineCardMedia.component';
|
|
9
9
|
import InlineCardMeta from './_InlineCardMeta.component';
|
|
10
10
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
11
|
+
import InlineCardSelectionContext from './_InlineCardSelection.context';
|
|
12
|
+
import { faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
11
13
|
const CardWrapper = styled.div `
|
|
12
14
|
position: relative;
|
|
13
15
|
height: 64px;
|
|
@@ -75,7 +77,38 @@ const CardActionBackground = styled(motion.div) `
|
|
|
75
77
|
left: 0;
|
|
76
78
|
pointer-events: none;
|
|
77
79
|
`;
|
|
78
|
-
const
|
|
80
|
+
const SelectChecked = styled.div `
|
|
81
|
+
position: absolute;
|
|
82
|
+
top: 0;
|
|
83
|
+
right: 0;
|
|
84
|
+
|
|
85
|
+
width: 0;
|
|
86
|
+
height: 0;
|
|
87
|
+
|
|
88
|
+
border-bottom: 48px solid transparent;
|
|
89
|
+
border-right: 48px solid ${(props) => props.theme.colours.statusInfo.main};
|
|
90
|
+
`;
|
|
91
|
+
const SelectIconContainer = styled.div `
|
|
92
|
+
position: absolute;
|
|
93
|
+
left: 0;
|
|
94
|
+
right: 0;
|
|
95
|
+
|
|
96
|
+
width: 48px;
|
|
97
|
+
height: 48px;
|
|
98
|
+
|
|
99
|
+
display: flex;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
align-items: center;
|
|
102
|
+
|
|
103
|
+
padding-left: 16px;
|
|
104
|
+
padding-bottom: 16px;
|
|
105
|
+
|
|
106
|
+
color: ${(props) => props.theme.colours.statusInfo.contrast};
|
|
107
|
+
`;
|
|
108
|
+
const InlineCard = ({ children, size, value, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }) => {
|
|
109
|
+
const { value: selectedValues, onToggle } = useContext(InlineCardSelectionContext);
|
|
110
|
+
const isSelectable = !!onToggle;
|
|
111
|
+
const isSelected = selectedValues?.length && value && selectedValues.includes(value);
|
|
79
112
|
const theme = useTheme();
|
|
80
113
|
const x = useMotionValue(0);
|
|
81
114
|
const [ref, bounds] = useMeasure();
|
|
@@ -90,9 +123,20 @@ const InlineCard = ({ children, size, onClick, gestureLeftIcon, gestureLeftVaria
|
|
|
90
123
|
onGestureLeft();
|
|
91
124
|
}
|
|
92
125
|
};
|
|
126
|
+
const handleClick = (e) => {
|
|
127
|
+
if (onClick) {
|
|
128
|
+
onClick(e);
|
|
129
|
+
}
|
|
130
|
+
if (onToggle && value) {
|
|
131
|
+
onToggle(value);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
93
134
|
return (React.createElement(CardWrapper, { size: size },
|
|
94
135
|
React.createElement(CardActionBackground, { style: { opacity, backgroundColor: gestureLeftTheme.main } }, gestureLeftIcon && (React.createElement(FontAwesomeIcon, { style: { fontSize: '20px', color: gestureLeftTheme.contrast }, icon: gestureLeftIcon }))),
|
|
95
|
-
React.createElement(CardOuter, { drag: onGestureLeft ? 'x' : undefined, onDragEnd: handleDragEnd, ref: ref, style: { x }, animate: { x: gestureLeftActivated ? -bounds.width : undefined, opacity: gestureLeftActivated ? 0 : undefined }, dragConstraints: { left: 0, right: 0 }, usePointer: !!onClick, onClick:
|
|
136
|
+
React.createElement(CardOuter, { drag: onGestureLeft ? 'x' : undefined, onDragEnd: handleDragEnd, ref: ref, style: { x }, animate: { x: gestureLeftActivated ? -bounds.width : undefined, opacity: gestureLeftActivated ? 0 : undefined }, dragConstraints: { left: 0, right: 0 }, usePointer: !!onClick || isSelectable, onClick: handleClick }, children),
|
|
137
|
+
isSelectable && isSelected ? (React.createElement(SelectChecked, null,
|
|
138
|
+
React.createElement(SelectIconContainer, null,
|
|
139
|
+
React.createElement(FontAwesomeIcon, { icon: faCheck })))) : null));
|
|
96
140
|
};
|
|
97
141
|
InlineCard.Media = InlineCardMedia;
|
|
98
142
|
InlineCard.Content = InlineCardContent;
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
import { Meta } from '@storybook/react/types-6-0';
|
|
3
3
|
export declare const Standard: () => JSX.Element;
|
|
4
4
|
export declare const WithDrag: () => JSX.Element;
|
|
5
|
+
export declare const WithSelection: () => JSX.Element;
|
|
5
6
|
declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
|
|
6
7
|
export default _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import { faCheckCircle, faExclamationTriangle, faInfoCircle, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
3
|
-
import { Badge, InlineCard, InlineCardGroup } from '../..';
|
|
3
|
+
import { Badge, FocusLayout, Form, InlineCard, InlineCardGroup } from '../..';
|
|
4
|
+
import InlineCardSelection from './InlineCardSelection.component';
|
|
4
5
|
export const Standard = () => (React.createElement(InlineCardGroup, null,
|
|
5
6
|
React.createElement(InlineCard, null,
|
|
6
7
|
React.createElement(InlineCard.Content, null, "Some content")),
|
|
@@ -14,7 +15,7 @@ export const Standard = () => (React.createElement(InlineCardGroup, null,
|
|
|
14
15
|
React.createElement(InlineCard.Content, null, "Clickable card"),
|
|
15
16
|
React.createElement(InlineCard.Meta, null,
|
|
16
17
|
React.createElement(Badge, { variant: 'info' }, "Clickable")))));
|
|
17
|
-
export const WithDrag = () => (React.createElement(
|
|
18
|
+
export const WithDrag = () => (React.createElement(FocusLayout, null,
|
|
18
19
|
React.createElement(InlineCardGroup, null,
|
|
19
20
|
React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faCheckCircle, gestureLeftVariant: 'success' },
|
|
20
21
|
React.createElement(InlineCard.Content, null, "A success gesture")),
|
|
@@ -24,6 +25,27 @@ export const WithDrag = () => (React.createElement("div", { style: { maxWidth: '
|
|
|
24
25
|
React.createElement(InlineCard.Content, null, "A warning gesture")),
|
|
25
26
|
React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faTimes, gestureLeftVariant: 'danger' },
|
|
26
27
|
React.createElement(InlineCard.Content, null, "A danger gesture")))));
|
|
28
|
+
export const WithSelection = () => {
|
|
29
|
+
const [value, setValue] = useState({ animals: ['lama'] });
|
|
30
|
+
return (React.createElement(FocusLayout, null,
|
|
31
|
+
React.createElement(Form, { value: value, onChange: setValue },
|
|
32
|
+
React.createElement(InlineCardSelection, { name: 'animals' },
|
|
33
|
+
React.createElement(InlineCardGroup, null,
|
|
34
|
+
React.createElement(InlineCard, { value: 'camel' },
|
|
35
|
+
React.createElement(InlineCard.Media, null,
|
|
36
|
+
React.createElement("img", { src: 'http://3.bp.blogspot.com/-m2w1bFhTLMs/Uyh0xlVCluI/AAAAAAAACjw/G4IhU8b0RhY/w1200-h630-p-k-nu/368692.jpg' })),
|
|
37
|
+
React.createElement(InlineCard.Content, null, "A cranky camel")),
|
|
38
|
+
React.createElement(InlineCard, { value: 'eagle' },
|
|
39
|
+
React.createElement(InlineCard.Media, null,
|
|
40
|
+
React.createElement("img", { src: 'https://www.hakaimagazine.com/wp-content/uploads/header-bald-eagle-nests.jpg' })),
|
|
41
|
+
React.createElement(InlineCard.Content, null, "A eager eagle")),
|
|
42
|
+
React.createElement(InlineCard, { value: 'lama' },
|
|
43
|
+
React.createElement(InlineCard.Media, null,
|
|
44
|
+
React.createElement("img", { src: 'https://external-preview.redd.it/3KAYF01HBUX-QKwcpo89kHPzScRoZPXZN7o02JepX8E.jpg?auto=webp&s=08bbddec975a8af76de43a33001604099fb0168d' })),
|
|
45
|
+
React.createElement(InlineCard.Content, null, "A lazy lama")),
|
|
46
|
+
React.createElement(InlineCard, { value: 'iguana' },
|
|
47
|
+
React.createElement(InlineCard.Content, null, "An invisible iguana")))))));
|
|
48
|
+
};
|
|
27
49
|
export default {
|
|
28
50
|
title: 'Components/InlineCard',
|
|
29
51
|
component: InlineCard,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface InlineCardSelectionProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
name: string;
|
|
5
|
+
value?: string[];
|
|
6
|
+
onChange?: (value: string[]) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const InlineCardSelection: ({ children, name, value: propsValue, onChange: propsOnChange, }: InlineCardSelectionProps) => JSX.Element;
|
|
9
|
+
export default InlineCardSelection;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import useFormNode from '../Form/useFormNode.hook';
|
|
3
|
+
import InlineCardSelectionContext from './_InlineCardSelection.context';
|
|
4
|
+
const InlineCardSelection = ({ children, name, value: propsValue, onChange: propsOnChange, }) => {
|
|
5
|
+
const { value: contextValue, onChange: contextOnChange } = useFormNode(name);
|
|
6
|
+
const value = contextValue || propsValue || [];
|
|
7
|
+
const wrappedOnChange = useCallback((val) => {
|
|
8
|
+
if (propsOnChange) {
|
|
9
|
+
propsOnChange(val);
|
|
10
|
+
}
|
|
11
|
+
if (contextOnChange) {
|
|
12
|
+
contextOnChange(val);
|
|
13
|
+
}
|
|
14
|
+
}, [propsOnChange, contextOnChange]);
|
|
15
|
+
const handleToggle = (_value) => {
|
|
16
|
+
if (!value) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (value.includes(_value)) {
|
|
20
|
+
wrappedOnChange(value.filter((val) => val !== _value));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
wrappedOnChange([...value, _value]);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return (React.createElement(InlineCardSelectionContext.Provider, { value: { value, onToggle: handleToggle } }, children));
|
|
27
|
+
};
|
|
28
|
+
export default InlineCardSelection;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type CardSize = 'fill' | 'xs' | 'sm' | 'md' | 'lg';
|
|
3
|
+
interface InlineCardSelectionContextProps {
|
|
4
|
+
value?: string[];
|
|
5
|
+
onToggle?: (value: string) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const InlineCardSelectionContext: import("react").Context<InlineCardSelectionContextProps>;
|
|
8
|
+
export default InlineCardSelectionContext;
|
package/build/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { default as Notifications } from './components/Notifications/Notificatio
|
|
|
14
14
|
export { default as ImageUpload } from './components/ImageUpload/ImageUpload.component';
|
|
15
15
|
export { default as InlineCard } from './components/InlineCard/InlineCard.component';
|
|
16
16
|
export { default as InlineCardGroup } from './components/InlineCard/InlineCardGroup.component';
|
|
17
|
+
export { default as InlineCardSelection } from './components/InlineCard/InlineCardSelection.component';
|
|
17
18
|
export { default as Input } from './components/Input/Input.component';
|
|
18
19
|
export { default as Heading } from './components/Heading/Heading.component';
|
|
19
20
|
export { default as LiveInput } from './components/LiveInput/LiveInput.component';
|
package/build/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export { default as Notifications } from './components/Notifications/Notificatio
|
|
|
14
14
|
export { default as ImageUpload } from './components/ImageUpload/ImageUpload.component';
|
|
15
15
|
export { default as InlineCard } from './components/InlineCard/InlineCard.component';
|
|
16
16
|
export { default as InlineCardGroup } from './components/InlineCard/InlineCardGroup.component';
|
|
17
|
+
export { default as InlineCardSelection } from './components/InlineCard/InlineCardSelection.component';
|
|
17
18
|
export { default as Input } from './components/Input/Input.component';
|
|
18
19
|
export { default as Heading } from './components/Heading/Heading.component';
|
|
19
20
|
export { default as LiveInput } from './components/LiveInput/LiveInput.component';
|