diff --git a/cashtab/src/components/Common/Switch.js b/cashtab/src/components/Common/Switch.js new file mode 100644 --- /dev/null +++ b/cashtab/src/components/Common/Switch.js @@ -0,0 +1,177 @@ +// Copyright (c) 2024 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +import React from 'react'; +import styled from 'styled-components'; +import PropTypes from 'prop-types'; + +const CheckBoxWrapper = styled.div` + position: relative; +`; +const CheckBoxLabel = styled.label` + position: absolute; + top: 0; + left: 0; + width: 42px; + height: 26px; + border-radius: 15px; + background: #bebebe; + cursor: pointer; + &::after { + content: ''; + display: block; + border-radius: 50%; + width: 18px; + height: 18px; + margin: 3px; + background: #ffffff; + box-shadow: 1px 3px 3px 1px rgba(0, 0, 0, 0.2); + transition: 0.4s; + } +`; +const CheckBox = styled.input` + opacity: 0; + z-index: 1; + border-radius: 15px; + width: 42px; + height: 26px; + &:checked + ${CheckBoxLabel} { + background: ${props => props.theme.eCashBlue}; + &::after { + content: ''; + display: block; + border-radius: 50%; + width: 18px; + height: 18px; + margin-left: 21px; + transition: 0.4s; + } + } +`; + +// TODO optimize transition time +// TODO width +// TODO mess with styles and colors +// TODO disabled label (accept image) +// TODO enabled label (accept image) +const CustomSwitch = ({ label, checked, handleToggle }) => { + return ( + + + + + ); +}; + +CustomSwitch.propTypes = { + label: PropTypes.string, + checked: PropTypes.bool, + handleToggle: PropTypes.func, +}; + +const ToggleSwitch = styled.div` + position: relative; + width: 75px; + display: inline-block; + vertical-align: middle; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + text-align: left; +`; +const SwitchLabel = styled.label` + display: block; + overflow: hidden; + cursor: pointer; + border: 0 solid #ccc; + border-radius: 20px; + margin: 0; +`; +const SwitchInner = styled.span` + display: block; + width: 200%; + margin-left: -100%; + &:before { + content: 'Yes'; + text-transform: uppercase; + padding-left: 10px; + background-color: ${props => props.theme.eCashBlue}; + color: #fff; + } + &::before, + &::after { + display: block; + float: left; + width: 50%; + height: 34px; + padding: 0; + line-height: 34px; + font-size: 14px; + color: white; + font-weight: bold; + box-sizing: border-box; + } + &::after { + content: 'No'; + text-transform: uppercase; + padding-right: 10px; + background-color: #ccc; + color: #fff; + text-align: right; + } +`; +const SwitchItself = styled.span` + display: block; + width: 24px; + margin: 5px; + background: #fff; + position: absolute; + top: 0; + bottom: 0; + right: 40px; + border: 0 solid #ccc; + border-radius: 20px; + transition: all 0.42s ease-in 0s; +`; +const SwitchInput = styled.input` + display: none; + &:checked + ${SwitchLabel} ${SwitchInner} { + margin-left: 0; + } + &:checked + ${SwitchLabel} ${SwitchItself} { + right: 0px; + } +`; + +export const BetaSwitch = ({ label, checked, handleToggle }) => { + return ( + + + + + + + + ); +}; + +BetaSwitch.propTypes = { + label: PropTypes.string, + checked: PropTypes.bool, + handleToggle: PropTypes.func, +}; + +export default CustomSwitch; diff --git a/cashtab/src/components/Send/SendXec.js b/cashtab/src/components/Send/SendXec.js --- a/cashtab/src/components/Send/SendXec.js +++ b/cashtab/src/components/Send/SendXec.js @@ -60,6 +60,7 @@ SendXecInput, TextArea, } from 'components/Common/Inputs'; +import CustomSwitch, { BetaSwitch } from 'components/Common/Switch'; const SwitchContainer = styled.div` display: flex; @@ -808,19 +809,35 @@ )} {!txInfoFromUrl && !('queryString' in parsedAddressInput) && ( - - Multiple Recipients:   - + + Multiple Recipients:   + { + setIsOneToManyXECSend(!isOneToManyXECSend); + // Do not persist multisend input to single send and vice versa + clearInputForms(); + }} + /> + + { - setIsOneToManyXECSend(!isOneToManyXECSend); - // Do not persist multisend input to single send and vice versa - clearInputForms(); - }} + handleToggle={() => + setIsOneToManyXECSend(!isOneToManyXECSend) + } /> - + + setIsOneToManyXECSend(!isOneToManyXECSend) + } + /> + )}