@dtdot/lego 0.15.1 → 0.16.3

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,16 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
1
+ import { motion, useMotionValue, useTransform } from 'framer-motion';
2
+ import React, { useState } from 'react';
3
+ import styled, { useTheme } from 'styled-components';
4
+ import useMeasure from 'react-use-measure';
3
5
  import { responsive } from '../..';
6
+ import getThemeStatusColour from '../../theme/helpers/getThemeStatusColour';
4
7
  import InlineCardContent from './_InlineCardContent.component';
5
8
  import InlineCardMedia from './_InlineCardMedia.component';
6
9
  import InlineCardMeta from './_InlineCardMeta.component';
7
- const CardOuter = styled.div `
10
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
11
+ const CardWrapper = styled.div `
12
+ position: relative;
8
13
  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
14
 
17
15
  ${(props) => {
18
16
  switch (props.size) {
@@ -52,8 +50,49 @@ const CardOuter = styled.div `
52
50
  }
53
51
  }}
54
52
  `;
55
- const InlineCard = ({ children, size, onClick }) => {
56
- return (React.createElement(CardOuter, { size: size, usePointer: !!onClick, onClick: onClick }, children));
53
+ const CardOuter = styled(motion.div) `
54
+ height: 64px;
55
+ width: 100%;
56
+ display: flex;
57
+
58
+ cursor: ${(props) => (props.usePointer ? 'pointer' : '')};
59
+
60
+ background-color: ${(props) => props.theme.colours.cardBackground};
61
+ box-shadow: ${(props) => props.theme.shadows.small};
62
+ `;
63
+ const CardActionBackground = styled(motion.div) `
64
+ position: absolute;
65
+ width: 100%;
66
+ height: 100%;
67
+
68
+ display: flex;
69
+ justify-content: flex-end;
70
+ align-items: center;
71
+ padding: 8px;
72
+ padding-right: 16px;
73
+
74
+ top: 0;
75
+ left: 0;
76
+ pointer-events: none;
77
+ `;
78
+ const InlineCard = ({ children, size, onClick, gestureLeftIcon, gestureLeftVariant, onGestureLeft, }) => {
79
+ const theme = useTheme();
80
+ const x = useMotionValue(0);
81
+ const [ref, bounds] = useMeasure();
82
+ const xInput = [-50, 0];
83
+ const gestureLeftTheme = getThemeStatusColour(gestureLeftVariant || 'info', theme);
84
+ const [gestureLeftActivated, setGestureLeftActivated] = useState(false);
85
+ const opacity = useTransform(x, xInput, ['1', '0']);
86
+ const handleDragEnd = (e, panInfo) => {
87
+ // approx xInputMin * 3
88
+ if (panInfo.offset.x < -180 && onGestureLeft) {
89
+ setGestureLeftActivated(true);
90
+ onGestureLeft();
91
+ }
92
+ };
93
+ return (React.createElement(CardWrapper, { size: size },
94
+ 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: onClick }, children)));
57
96
  };
58
97
  InlineCard.Media = InlineCardMedia;
59
98
  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,
@@ -1,10 +1,10 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
- import { animated, useTransition } from 'react-spring';
5
4
  import { Notification, Spacer } from '../..';
6
5
  import responsive from '../../responsive/responsive';
7
6
  import zIndexConstants from '../../constants/zIndex.constants';
7
+ import { AnimatePresence, motion } from 'framer-motion';
8
8
  const NotificationContainer = styled.div `
9
9
  position: fixed;
10
10
  bottom: 20px;
@@ -20,18 +20,9 @@ const NotificationContainer = styled.div `
20
20
  `)}
21
21
  `;
22
22
  const Notifications = ({ notifications }) => {
23
- const transitions = useTransition(notifications, (item) => item.id, {
24
- from: { transform: 'translateX(-300px)', opacity: 0 },
25
- enter: { transform: 'translateX(0px)', opacity: 1 },
26
- leave: { transform: 'translateX(300px)', opacity: 0 },
27
- config: {
28
- tension: 280,
29
- mass: 0.2,
30
- friction: 10,
31
- },
32
- });
33
- return (React.createElement(NotificationContainer, null, transitions.map(({ item, props, key }) => (React.createElement(animated.div, { key: key, style: props },
34
- React.createElement(Spacer, { size: '1x' }),
35
- React.createElement(Notification, { variant: item.variant, message: item.message, action: item.action, onAction: item.onAction, count: item.count }))))));
23
+ return (React.createElement(NotificationContainer, null,
24
+ React.createElement(AnimatePresence, null, notifications.map((notification) => (React.createElement(motion.div, { transition: { type: 'spring', duration: 0.4, bounce: 0 }, initial: { x: -300, opacity: 0 }, animate: { x: 0, opacity: 1 }, exit: { x: 300, opacity: 0 }, key: notification.id },
25
+ React.createElement(Spacer, { size: '1x' }),
26
+ React.createElement(Notification, { variant: notification.variant, message: notification.message, action: notification.action, onAction: notification.onAction, count: notification.count })))))));
36
27
  };
37
28
  export default Notifications;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "0.15.1",
3
+ "version": "0.16.3",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -59,7 +59,7 @@
59
59
  "framer-motion": "^4.1.17",
60
60
  "identicon.js": "^2.3.3",
61
61
  "qrcode": "^1.4.4",
62
- "react-spring": "^8.0.27",
62
+ "react-use-measure": "^2.1.1",
63
63
  "spark-md5": "^3.0.1"
64
64
  }
65
65
  }