@dtdot/lego 2.0.0-40 → 2.0.0-42
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/FloatingActionButton/FloatingActionButton.component.d.ts +5 -2
- package/build/components/FloatingActionButton/FloatingActionButton.component.js +18 -40
- package/build/components/FloatingActionButton/_FloatingActionButton.context.d.ts +15 -0
- package/build/components/FloatingActionButton/_FloatingActionButton.context.js +6 -0
- package/build/components/FloatingActionButton/_FloatingActionButton.internal.d.ts +10 -0
- package/build/components/FloatingActionButton/_FloatingActionButton.internal.js +45 -0
- package/build/components/FloatingActionButton/_FloatingActionButton.provider.d.ts +6 -0
- package/build/components/FloatingActionButton/_FloatingActionButton.provider.js +15 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
3
3
|
import { ColourVariant } from '../../theme/theme.types';
|
|
4
4
|
interface FloatingActionButtonProps {
|
|
@@ -6,5 +6,8 @@ interface FloatingActionButtonProps {
|
|
|
6
6
|
onClick: () => void;
|
|
7
7
|
variant?: ColourVariant;
|
|
8
8
|
}
|
|
9
|
-
declare const FloatingActionButton:
|
|
9
|
+
declare const FloatingActionButton: {
|
|
10
|
+
({ icon, onClick, variant }: FloatingActionButtonProps): JSX.Element | null;
|
|
11
|
+
Provider: ({ children }: import("./_FloatingActionButton.provider").FloatingActionButtonProviderProps) => JSX.Element;
|
|
12
|
+
};
|
|
10
13
|
export default FloatingActionButton;
|
|
@@ -1,43 +1,21 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import MinimalMenuContext from '../MinimalMenu/MinimalMenu.context';
|
|
7
|
-
import zIndexConstants from '../../constants/zIndex.constants';
|
|
8
|
-
const FloatingButton = styled(motion.button) `
|
|
9
|
-
position: fixed;
|
|
10
|
-
bottom: ${(props) => (props.offsetBottom ? '76px' : '20px')};
|
|
11
|
-
right: 20px;
|
|
12
|
-
width: 56px;
|
|
13
|
-
height: 56px;
|
|
14
|
-
border-radius: 50%;
|
|
15
|
-
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).main};
|
|
16
|
-
color: ${(props) => getThemeVariantColours(props.variant, props.theme).contrastText};
|
|
17
|
-
border: none;
|
|
18
|
-
outline: none;
|
|
19
|
-
cursor: pointer;
|
|
20
|
-
display: flex;
|
|
21
|
-
justify-content: center;
|
|
22
|
-
align-items: center;
|
|
23
|
-
font-size: 24px;
|
|
24
|
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
|
|
25
|
-
z-index: ${zIndexConstants.floatingActionButton};
|
|
26
|
-
|
|
27
|
-
&:hover {
|
|
28
|
-
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).darker};
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
1
|
+
import React, { useContext, useEffect, useMemo } from 'react';
|
|
2
|
+
import FloatingActionButtonContext from './_FloatingActionButton.context';
|
|
3
|
+
import FloatingActionButtonProvider from './_FloatingActionButton.provider';
|
|
4
|
+
import { v4 } from 'uuid';
|
|
5
|
+
import FloatingActionButtonInternal from './_FloatingActionButton.internal';
|
|
31
6
|
const FloatingActionButton = ({ icon, onClick, variant = 'primary' }) => {
|
|
32
|
-
const {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
React.createElement(
|
|
7
|
+
const { contextExists, setButton } = useContext(FloatingActionButtonContext);
|
|
8
|
+
const id = useMemo(() => v4(), []);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setButton({ id, icon, onClick, variant });
|
|
11
|
+
return () => {
|
|
12
|
+
setButton(undefined);
|
|
13
|
+
};
|
|
14
|
+
}, [icon, onClick, variant, setButton]);
|
|
15
|
+
if (!contextExists) {
|
|
16
|
+
return React.createElement(FloatingActionButtonInternal, { icon: icon, onClick: onClick, variant: variant });
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
42
19
|
};
|
|
20
|
+
FloatingActionButton.Provider = FloatingActionButtonProvider;
|
|
43
21
|
export default FloatingActionButton;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
3
|
+
import { ColourVariant } from '../../theme/theme.types';
|
|
4
|
+
export interface FabProps {
|
|
5
|
+
id: string;
|
|
6
|
+
icon: IconDefinition | null;
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
variant?: ColourVariant;
|
|
9
|
+
}
|
|
10
|
+
interface FloatingActionButtonContextProps {
|
|
11
|
+
contextExists: boolean;
|
|
12
|
+
setButton: (props: FabProps | undefined) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const FloatingActionButtonContext: import("react").Context<FloatingActionButtonContextProps>;
|
|
15
|
+
export default FloatingActionButtonContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
3
|
+
import { ColourVariant } from '../../theme/theme.types';
|
|
4
|
+
interface FloatingActionButtonInternalProps {
|
|
5
|
+
icon: IconDefinition;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
variant?: ColourVariant;
|
|
8
|
+
}
|
|
9
|
+
declare const FloatingActionButtonInternal: ({ icon, onClick, variant }: FloatingActionButtonInternalProps) => JSX.Element;
|
|
10
|
+
export default FloatingActionButtonInternal;
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
import zIndexConstants from '../../constants/zIndex.constants';
|
|
8
|
+
import FloatingActionButtonContext from './_FloatingActionButton.context';
|
|
9
|
+
const FloatingButton = styled(motion.button) `
|
|
10
|
+
position: fixed;
|
|
11
|
+
bottom: ${(props) => (props.offsetBottom ? '76px' : '20px')};
|
|
12
|
+
right: 20px;
|
|
13
|
+
width: 56px;
|
|
14
|
+
height: 56px;
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).main};
|
|
17
|
+
color: ${(props) => getThemeVariantColours(props.variant, props.theme).contrastText};
|
|
18
|
+
border: none;
|
|
19
|
+
outline: none;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
align-items: center;
|
|
24
|
+
font-size: 24px;
|
|
25
|
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
|
|
26
|
+
z-index: ${zIndexConstants.floatingActionButton};
|
|
27
|
+
|
|
28
|
+
&:hover {
|
|
29
|
+
background-color: ${(props) => getThemeVariantColours(props.variant, props.theme).darker};
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
const FloatingActionButtonInternal = ({ icon, onClick, variant = 'primary' }) => {
|
|
33
|
+
const { menuExists, isMobile } = useContext(MinimalMenuContext);
|
|
34
|
+
const { contextExists } = useContext(FloatingActionButtonContext);
|
|
35
|
+
const variants = {
|
|
36
|
+
hidden: { opacity: 0, scale: 0 },
|
|
37
|
+
visible: { opacity: 1, scale: 1, transition: { duration: 0.3, delay: 0.2 } },
|
|
38
|
+
exit: { opacity: 0, scale: 0, transition: { duration: 0.3 } },
|
|
39
|
+
hover: { scale: 1.1 },
|
|
40
|
+
tap: { scale: 0.95 },
|
|
41
|
+
};
|
|
42
|
+
return (React.createElement(FloatingButton, { key: 'floating-button', initial: contextExists ? 'hidden' : 'visible', animate: 'visible', exit: 'exit', whileHover: 'hover', whileTap: 'tap', offsetBottom: menuExists && isMobile, variants: variants, onClick: onClick, variant: variant },
|
|
43
|
+
React.createElement(FontAwesomeIcon, { icon: icon })));
|
|
44
|
+
};
|
|
45
|
+
export default FloatingActionButtonInternal;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface FloatingActionButtonProviderProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
declare const FloatingActionButtonProvider: ({ children }: FloatingActionButtonProviderProps) => JSX.Element;
|
|
6
|
+
export default FloatingActionButtonProvider;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
|
+
import { AnimatePresence } from 'framer-motion';
|
|
3
|
+
import FloatingActionButtonContext from './_FloatingActionButton.context';
|
|
4
|
+
import FloatingActionButtonInternal from './_FloatingActionButton.internal';
|
|
5
|
+
const FloatingActionButtonProvider = ({ children }) => {
|
|
6
|
+
const [fab, setFab] = useState();
|
|
7
|
+
const contextVal = useMemo(() => ({
|
|
8
|
+
contextExists: true,
|
|
9
|
+
setButton: setFab,
|
|
10
|
+
}), [setFab]);
|
|
11
|
+
return (React.createElement(FloatingActionButtonContext.Provider, { value: contextVal },
|
|
12
|
+
children,
|
|
13
|
+
React.createElement(AnimatePresence, null, fab?.icon && (React.createElement(FloatingActionButtonInternal, { key: fab.id, icon: fab.icon, onClick: fab.onClick, variant: fab.variant })))));
|
|
14
|
+
};
|
|
15
|
+
export default FloatingActionButtonProvider;
|