@dtdot/lego 2.0.0-36 → 2.0.0-38

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.
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
3
+ import { ColourVariant } from '../../theme/theme.types';
4
+ interface FloatingActionButtonProps {
5
+ icon: IconDefinition;
6
+ onClick: () => void;
7
+ variant?: ColourVariant;
8
+ }
9
+ declare const FloatingActionButton: React.FC<FloatingActionButtonProps>;
10
+ export default FloatingActionButton;
@@ -0,0 +1,42 @@
1
+ import React, { useContext } from 'react';
2
+ import styled from 'styled-components';
3
+ import { motion } from 'framer-motion';
4
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
+ import getThemeVariantColours from '../../theme/helpers/getThemeVariantColours';
6
+ import MinimalMenuContext from '../MinimalMenu/MinimalMenu.context';
7
+ const FloatingButton = styled(motion.button) `
8
+ position: fixed;
9
+ bottom: ${(props) => (props.offsetBottom ? '76px' : '20px')};
10
+ right: 20px;
11
+ width: 60px;
12
+ height: 60px;
13
+ border-radius: 50%;
14
+ background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).main};
15
+ color: ${(props) => getThemeVariantColours(props.variant, props.theme).contrastText};
16
+ border: none;
17
+ outline: none;
18
+ cursor: pointer;
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ font-size: 24px;
23
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
24
+ z-index: 999;
25
+
26
+ &:hover {
27
+ background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).darker};
28
+ }
29
+ `;
30
+ const FloatingActionButton = ({ icon, onClick, variant = 'primary' }) => {
31
+ const { menuExists, isMobile } = useContext(MinimalMenuContext);
32
+ const variants = {
33
+ hidden: { opacity: 0, scale: 0 },
34
+ visible: { opacity: 1, scale: 1, transition: { duration: 0.3, delay: 0.2 } },
35
+ exit: { opacity: 0, scale: 0 },
36
+ hover: { scale: 1.05 },
37
+ tap: { scale: 0.95 },
38
+ };
39
+ return (React.createElement(FloatingButton, { initial: 'hidden', animate: 'visible', exit: 'exit', whileHover: 'hover', whileTap: 'tap', offsetBottom: menuExists && isMobile, variants: variants, onClick: onClick, variant: variant },
40
+ React.createElement(FontAwesomeIcon, { icon: icon })));
41
+ };
42
+ export default FloatingActionButton;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ interface MinimalMenuContextProps {
3
+ menuExists: boolean;
4
+ isMobile: boolean;
5
+ }
6
+ declare const MinimalMenuContext: React.Context<MinimalMenuContextProps>;
7
+ export default MinimalMenuContext;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ const MinimalMenuContext = React.createContext({
3
+ menuExists: false,
4
+ isMobile: false,
5
+ });
6
+ export default MinimalMenuContext;
@@ -1,6 +1,7 @@
1
- import React from 'react';
1
+ import React, { useMemo } from 'react';
2
2
  import styled from 'styled-components';
3
- import responsive from '../../responsive/responsive';
3
+ import responsive, { useIsScreenSize } from '../../responsive/responsive';
4
+ import MinimalMenuContext from './MinimalMenu.context';
4
5
  const MinimalMenuPageContainer = styled.div `
5
6
  ${responsive.useStylesFor('tablet').andLarger(`
6
7
  padding-left: 64px;
@@ -17,6 +18,12 @@ const MinimalMenuPageContainer = styled.div `
17
18
  `}
18
19
  `;
19
20
  const MinimalMenuPage = ({ children, hiddenMenu }) => {
20
- return React.createElement(MinimalMenuPageContainer, { hiddenMenu: !!hiddenMenu }, children);
21
+ const isMobile = useIsScreenSize('mobile');
22
+ const contextState = useMemo(() => ({
23
+ menuExists: true,
24
+ isMobile,
25
+ }), [isMobile]);
26
+ return (React.createElement(MinimalMenuContext.Provider, { value: contextState },
27
+ React.createElement(MinimalMenuPageContainer, { hiddenMenu: !!hiddenMenu }, children)));
21
28
  };
22
29
  export default MinimalMenuPage;
@@ -13,7 +13,7 @@ const MobileMinimalMenuOuter = styled.div `
13
13
  justify-content: space-evenly;
14
14
  align-items: center;
15
15
 
16
- background-color: ${(props) => props.theme.colours.background};
16
+ background-color: ${(props) => props.theme.colours.cardBackground};
17
17
  `;
18
18
  const MobileMinimalMenuContainer = ({ children }) => {
19
19
  return React.createElement(MobileMinimalMenuOuter, null, children);
@@ -19,18 +19,22 @@ const MotionDivContainer = styled(motion.div) `
19
19
  display: flex;
20
20
  flex-direction: column;
21
21
  justify-content: center;
22
+ align-items: center;
22
23
 
23
24
  padding-top: 3px;
24
25
  `;
25
26
  const TextDiv = styled.div `
26
- font-size: 11px;
27
+ font-size: 12px;
27
28
  padding-top: 6px;
28
29
  `;
30
+ const StyledIcon = styled(FontAwesomeIcon) `
31
+ font-size: 22px;
32
+ `;
29
33
  const iconContainerVariants = {
30
34
  base: { color: darkTheme.colours.defaultFont },
31
35
  active: { color: darkTheme.colours.primary.hover },
32
36
  };
33
37
  const MobileMinimalMenuItem = ({ icon, label, active, onClick, 'data-testid': dataTestId, }) => (React.createElement(ItemContainer, { onClick: onClick, "data-testid": dataTestId || 'menu-item' }, icon && (React.createElement(MotionDivContainer, { animate: active ? 'active' : 'base', variants: iconContainerVariants, transition: mobileMenuDefaultTransition },
34
- React.createElement(FontAwesomeIcon, { icon: icon }),
38
+ React.createElement(StyledIcon, { icon: icon }),
35
39
  React.createElement(TextDiv, null, label)))));
36
40
  export default MobileMinimalMenuItem;
package/build/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export { default as Checklist } from './components/Checklist/Checklist.component
14
14
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
15
15
  export { default as ControlLine } from './components/ControlLine/ControlLine.component';
16
16
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
17
- export { default as FloatingAction } from './components/FloatingAction/FloatingAction.component';
17
+ export { default as FloatingActionButton } from './components/FloatingActionButton/FloatingActionButton.component';
18
18
  export { default as Form } from './components/Form/Form.component';
19
19
  export { default as Notification } from './components/Notification/Notification.component';
20
20
  export { default as Notifications } from './components/Notifications/Notifications.component';
package/build/index.js CHANGED
@@ -14,7 +14,7 @@ export { default as Checklist } from './components/Checklist/Checklist.component
14
14
  export { default as ControlGroup } from './components/ControlGroup/ControlGroup.component';
15
15
  export { default as ControlLine } from './components/ControlLine/ControlLine.component';
16
16
  export { default as FancyCheckbox } from './components/FancyCheckbox/FancyCheckbox.component';
17
- export { default as FloatingAction } from './components/FloatingAction/FloatingAction.component';
17
+ export { default as FloatingActionButton } from './components/FloatingActionButton/FloatingActionButton.component';
18
18
  export { default as Form } from './components/Form/Form.component';
19
19
  export { default as Notification } from './components/Notification/Notification.component';
20
20
  export { default as Notifications } from './components/Notifications/Notifications.component';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "2.0.0-36",
3
+ "version": "2.0.0-38",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- interface FloatingActionProps {
3
- children: React.ReactNode;
4
- threshold?: number;
5
- }
6
- declare const FloatingAction: ({ children }: FloatingActionProps) => JSX.Element;
7
- export default FloatingAction;
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
- const FloatingActionContainer = styled.div `
4
- position: sticky;
5
- bottom: 0;
6
- background-color: ${(props) => props.theme.colours.background};
7
- `;
8
- const FloatingAction = ({ children }) => {
9
- return React.createElement(FloatingActionContainer, null, children);
10
- };
11
- export default FloatingAction;