From d986bf35ee304010550a640aefb48e3df8bcf2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sat, 19 Feb 2022 22:21:55 +0400 Subject: [PATCH] Create PaymentMethod component --- components/soutyen/payment-method.js | 117 +++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 components/soutyen/payment-method.js diff --git a/components/soutyen/payment-method.js b/components/soutyen/payment-method.js new file mode 100644 index 0000000..0a844ec --- /dev/null +++ b/components/soutyen/payment-method.js @@ -0,0 +1,117 @@ +import {useEffect, useMemo} from 'react' +import PropTypes from 'prop-types' +import clsx from 'clsx' +import {styled} from '@mui/system' +import {useSwitch} from '@mui/base/SwitchUnstyled' + +const green = { + 700: '#4CAF50', +} + +const grey = { + 400: '#BFC7CF', + 800: '#2F3A45', +} + +const SwitchRoot = styled('span')` + display: inline-block; + position: relative; + width: 84px; + height: 36px; + padding: 8px; +` + +const SwitchInput = styled('input')` + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; + opacity: 0; + z-index: 1; + margin: 0; + cursor: pointer; +` + +const SwitchThumb = styled('span')` + position: absolute; + display: block; + background-color: ${green[700]}; + width: 40px; + height: 40px; + border-radius: 8px; + top: -1px; + left: 4px; + transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); + + &::before { + display: block; + content: ''; + width: 100%; + height: 100%; + background: url('data:image/svg+xml;utf8,') + center center no-repeat; + } + + &.focusVisible { + background-color: #79b; + } + + &.checked { + transform: translateX(44px); + + &::before { + background-image: url('data:image/svg+xml;utf8,'); + } + } +` + +const SwitchTrack = styled('span')( + ({theme}) => ` + background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[400]}; + border-radius: 4px; + width: 100%; + height: 100%; + display: block; +`, +) + +function MUISwitch(props) { + const {setIsPaypal} = props + const {getInputProps, checked, disabled, focusVisible} = useSwitch(props) + + const stateClasses = useMemo(() => ({ + checked, + disabled, + focusVisible, + }), [checked, disabled, focusVisible]) + + useEffect(() => { + setIsPaypal(stateClasses.checked) + }, [setIsPaypal, stateClasses]) + + return ( + + + + + + + ) +} + +MUISwitch.propTypes = { + setIsPaypal: PropTypes.func.isRequired +} + +export default function PaymentMethod({setIsPaypal}) { + return +} + +PaymentMethod.propTypes = { + setIsPaypal: PropTypes.func.isRequired +}