@dtdot/lego 0.15.1 → 0.16.0

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,11 +1,17 @@
1
1
  import React from 'react';
2
+ import { IconProp } from '@fortawesome/fontawesome-svg-core';
3
+ import { Status } from '../../theme/theme.types';
2
4
  export declare type InlineCardSize = 'fill' | 'xs' | 'sm' | 'md' | 'lg';
5
+ export declare type DragVariant = Status;
3
6
  export interface InlineCardProps extends React.HTMLAttributes<HTMLDivElement> {
4
7
  children: React.ReactNode;
5
8
  size?: InlineCardSize;
9
+ gestureLeftIcon?: IconProp;
10
+ gestureLeftVariant?: DragVariant;
11
+ onGestureLeft?: () => void;
6
12
  }
7
13
  declare const InlineCard: {
8
- ({ children, size, onClick }: InlineCardProps): JSX.Element;
14
+ ({ children, size, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }: InlineCardProps): JSX.Element;
9
15
  Media: ({ children }: import("./_InlineCardMedia.component").InlineCardMediaProps) => JSX.Element;
10
16
  Content: ({ children, center }: import("./_InlineCardContent.component").InlineCardContentProps) => JSX.Element;
11
17
  Meta: ({ children }: import("./_InlineCardMeta.component").InlineCardMetaProps) => JSX.Element;
@@ -1,18 +1,15 @@
1
+ import { motion, useMotionValue, useTransform } from 'framer-motion';
1
2
  import React from 'react';
2
- import styled from 'styled-components';
3
+ import styled, { useTheme } from 'styled-components';
3
4
  import { responsive } from '../..';
5
+ import getThemeStatusColour from '../../theme/helpers/getThemeStatusColour';
4
6
  import InlineCardContent from './_InlineCardContent.component';
5
7
  import InlineCardMedia from './_InlineCardMedia.component';
6
8
  import InlineCardMeta from './_InlineCardMeta.component';
7
- const CardOuter = styled.div `
9
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
+ const CardWrapper = styled.div `
11
+ position: relative;
8
12
  height: 64px;
9
- width: 100%;
10
- display: flex;
11
-
12
- cursor: ${(props) => (props.usePointer ? 'pointer' : '')};
13
-
14
- background-color: ${(props) => props.theme.colours.cardBackground};
15
- box-shadow: ${(props) => props.theme.shadows.small};
16
13
 
17
14
  ${(props) => {
18
15
  switch (props.size) {
@@ -52,8 +49,46 @@ const CardOuter = styled.div `
52
49
  }
53
50
  }}
54
51
  `;
55
- const InlineCard = ({ children, size, onClick }) => {
56
- return (React.createElement(CardOuter, { size: size, usePointer: !!onClick, onClick: onClick }, children));
52
+ const CardOuter = styled(motion.div) `
53
+ height: 64px;
54
+ width: 100%;
55
+ display: flex;
56
+
57
+ cursor: ${(props) => (props.usePointer ? 'pointer' : '')};
58
+
59
+ background-color: ${(props) => props.theme.colours.cardBackground};
60
+ box-shadow: ${(props) => props.theme.shadows.small};
61
+ `;
62
+ const CardActionBackground = styled(motion.div) `
63
+ position: absolute;
64
+ width: 100%;
65
+ height: 100%;
66
+
67
+ display: flex;
68
+ justify-content: flex-end;
69
+ align-items: center;
70
+ padding: 8px;
71
+ padding-right: 16px;
72
+
73
+ top: 0;
74
+ left: 0;
75
+ pointer-events: none;
76
+ `;
77
+ const InlineCard = ({ children, size, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }) => {
78
+ const theme = useTheme();
79
+ const x = useMotionValue(0);
80
+ const xInput = [-70, 0];
81
+ const gestureLeftTheme = getThemeStatusColour(gestureLeftVariant || 'info', theme);
82
+ const opacity = useTransform(x, xInput, ['1', '0']);
83
+ const handleDragEnd = (e, panInfo) => {
84
+ // approx xInputMin * 3
85
+ if (panInfo.offset.x < -180 && onGestureLeft) {
86
+ onGestureLeft();
87
+ }
88
+ };
89
+ return (React.createElement(CardWrapper, { size: size },
90
+ React.createElement(CardActionBackground, { style: { opacity, backgroundColor: gestureLeftTheme.main } }, gestureLeftIcon && (React.createElement(FontAwesomeIcon, { style: { fontSize: '20px', color: gestureLeftTheme.contrast }, icon: gestureLeftIcon }))),
91
+ React.createElement(CardOuter, { drag: onGestureLeft ? 'x' : undefined, onDragEnd: handleDragEnd, style: { x }, dragConstraints: { left: 0, right: 0 }, usePointer: !!onClick, onClick: onClick }, children)));
57
92
  };
58
93
  InlineCard.Media = InlineCardMedia;
59
94
  InlineCard.Content = InlineCardContent;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Meta } from '@storybook/react/types-6-0';
3
3
  export declare const Standard: () => JSX.Element;
4
+ export declare const WithDrag: () => JSX.Element;
4
5
  declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
5
6
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { faCheckCircle, faExclamationTriangle, faInfoCircle, faTimes } from '@fortawesome/free-solid-svg-icons';
2
3
  import { Badge, InlineCard, InlineCardGroup } from '../..';
3
4
  export const Standard = () => (React.createElement(InlineCardGroup, null,
4
5
  React.createElement(InlineCard, null,
@@ -13,6 +14,16 @@ export const Standard = () => (React.createElement(InlineCardGroup, null,
13
14
  React.createElement(InlineCard.Content, null, "Clickable card"),
14
15
  React.createElement(InlineCard.Meta, null,
15
16
  React.createElement(Badge, { variant: 'info' }, "Clickable")))));
17
+ export const WithDrag = () => (React.createElement("div", { style: { maxWidth: '400px' } },
18
+ React.createElement(InlineCardGroup, null,
19
+ React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faCheckCircle, gestureLeftVariant: 'success' },
20
+ React.createElement(InlineCard.Content, null, "A success gesture")),
21
+ React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faInfoCircle, gestureLeftVariant: 'info' },
22
+ React.createElement(InlineCard.Content, null, "A info gesture")),
23
+ React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faExclamationTriangle, gestureLeftVariant: 'warn' },
24
+ React.createElement(InlineCard.Content, null, "A warning gesture")),
25
+ React.createElement(InlineCard, { onGestureLeft: () => console.log('Gesture left triggered'), gestureLeftIcon: faTimes, gestureLeftVariant: 'danger' },
26
+ React.createElement(InlineCard.Content, null, "A danger gesture")))));
16
27
  export default {
17
28
  title: 'Components/InlineCard',
18
29
  component: InlineCard,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {