Commit 98d25dd2 authored by Moody Salem's avatar Moody Salem

perf(cleanup): remove the material ui dependency for the input range

parent f289dec6
import React from 'react' import React, { useCallback } from 'react'
import Slider from '@material-ui/core/Slider' import styled from 'styled-components'
import { withStyles } from '@material-ui/core/styles'
const StyledRangeInput = styled.input<{ value: number }>`
const StyledSlider = withStyles({ -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
root: { width: 100%; /* Specific width is required for Firefox. */
width: '90%', background: transparent; /* Otherwise white in Chrome */
color: '#565A69', cursor: pointer;
height: 4,
marginLeft: '15px', &:focus {
marginRight: '15px', outline: none;
padding: '15px 0' }
},
thumb: { &::-moz-focus-outer {
height: 28, border: 0;
width: 28, }
backgroundColor: '#565A69',
marginTop: -14, &::-webkit-slider-thumb {
marginLeft: -14, -webkit-appearance: none;
'&:focus,&:hover,&$active': { height: 28px;
boxShadow: width: 28px;
'0px 0px 1px rgba(0, 0, 0, 0.04), 0px 4px 8px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04), 0px 24px 32px rgba(0, 0, 0, 0.04)', background-color: #565a69;
// Reset on touch devices, it doesn't add specificity border-radius: 100%;
'@media (hover: none)': {} border: none;
transform: translateY(-50%);
color: ${({ theme }) => theme.bg1};
&:hover,
&:focus {
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1), 0px 4px 8px rgba(0, 0, 0, 0.08), 0px 16px 24px rgba(0, 0, 0, 0.06),
0px 24px 32px rgba(0, 0, 0, 0.04);
}
}
&::-moz-range-thumb {
height: 28px;
width: 28px;
background-color: #565a69;
border-radius: 100%;
border: none;
color: ${({ theme }) => theme.bg1};
&:hover,
&:focus {
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1), 0px 4px 8px rgba(0, 0, 0, 0.08), 0px 16px 24px rgba(0, 0, 0, 0.06),
0px 24px 32px rgba(0, 0, 0, 0.04);
} }
},
active: {},
track: {
height: 4
},
rail: {
height: 2,
opacity: 0.5,
backgroundColor: '#C3C5CB'
},
mark: {
backgroundColor: '#C3C5CB',
height: 12,
width: 2,
marginTop: -4
},
markActive: {
opacity: 1,
backgroundColor: 'currentColor',
height: 12,
width: 2,
marginTop: -4
} }
})(Slider)
&::-ms-thumb {
height: 28px;
width: 28px;
background-color: #565a69;
border-radius: 100%;
color: ${({ theme }) => theme.bg1};
&:hover,
&:focus {
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.1), 0px 4px 8px rgba(0, 0, 0, 0.08), 0px 16px 24px rgba(0, 0, 0, 0.06),
0px 24px 32px rgba(0, 0, 0, 0.04);
}
}
&::-webkit-slider-runnable-track {
background: linear-gradient(
90deg,
${({ theme }) => theme.bg5},
${({ theme }) => theme.bg5} ${({ value }) => value}%,
${({ theme }) => theme.bg3} ${({ value }) => value}%,
${({ theme }) => theme.bg3}
);
height: 2px;
}
&::-moz-range-track {
background: linear-gradient(
90deg,
${({ theme }) => theme.bg5},
${({ theme }) => theme.bg5} ${({ value }) => value}%,
${({ theme }) => theme.bg3} ${({ value }) => value}%,
${({ theme }) => theme.bg3}
);
height: 2px;
}
&::-ms-track {
width: 100%;
border-color: transparent;
color: transparent;
background: ${({ theme }) => theme.bg5};
height: 2px;
}
&::-ms-fill-lower {
background: ${({ theme }) => theme.bg5};
}
&::-ms-fill-upper {
background: ${({ theme }) => theme.bg3};
}
`
interface InputSliderProps { interface InputSliderProps {
value: number value: number
...@@ -54,8 +105,23 @@ interface InputSliderProps { ...@@ -54,8 +105,23 @@ interface InputSliderProps {
} }
export default function InputSlider({ value, onChange }: InputSliderProps) { export default function InputSlider({ value, onChange }: InputSliderProps) {
function wrappedOnChange(_, value) { const changeCallback = useCallback(
onChange(value) e => {
} onChange(e.target.value)
return <StyledSlider value={value} onChange={wrappedOnChange} aria-labelledby="input-slider" step={1} /> },
[onChange]
)
return (
<StyledRangeInput
type="range"
value={value}
style={{ width: '90%', marginLeft: 15, marginRight: 15, padding: '15px 0' }}
onChange={changeCallback}
aria-labelledby="input-slider"
step={1}
min={0}
max={100}
/>
)
} }
import { splitSignature } from '@ethersproject/bytes' import { splitSignature } from '@ethersproject/bytes'
import { Contract } from '@ethersproject/contracts' import { Contract } from '@ethersproject/contracts'
import { Percent, WETH } from '@uniswap/sdk' import { Percent, WETH } from '@uniswap/sdk'
import React, { useContext, useState } from 'react' import React, { useCallback, useContext, useState } from 'react'
import { ArrowDown, Plus } from 'react-feather' import { ArrowDown, Plus } from 'react-feather'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
import { RouteComponentProps } from 'react-router' import { RouteComponentProps } from 'react-router'
...@@ -384,6 +384,13 @@ export default function RemoveLiquidity({ match: { params } }: RouteComponentPro ...@@ -384,6 +384,13 @@ export default function RemoveLiquidity({ match: { params } }: RouteComponentPro
tokens[Field.TOKEN_A]?.symbol tokens[Field.TOKEN_A]?.symbol
} and ${parsedAmounts[Field.TOKEN_B]?.toSignificant(6)} ${tokens[Field.TOKEN_B]?.symbol}` } and ${parsedAmounts[Field.TOKEN_B]?.toSignificant(6)} ${tokens[Field.TOKEN_B]?.symbol}`
const liquidityPercentChangeCallback = useCallback(
(value: number) => {
onUserInput(Field.LIQUIDITY_PERCENT, value.toString())
},
[onUserInput]
)
return ( return (
<> <>
<AppBody> <AppBody>
...@@ -426,9 +433,7 @@ export default function RemoveLiquidity({ match: { params } }: RouteComponentPro ...@@ -426,9 +433,7 @@ export default function RemoveLiquidity({ match: { params } }: RouteComponentPro
<> <>
<Slider <Slider
value={Number.parseInt(parsedAmounts[Field.LIQUIDITY_PERCENT].toFixed(0))} value={Number.parseInt(parsedAmounts[Field.LIQUIDITY_PERCENT].toFixed(0))}
onChange={value => { onChange={liquidityPercentChangeCallback}
onUserInput(Field.LIQUIDITY_PERCENT, value.toString())
}}
/> />
<RowBetween> <RowBetween>
<MaxButton onClick={() => onUserInput(Field.LIQUIDITY_PERCENT, '25')} width="20%"> <MaxButton onClick={() => onUserInput(Field.LIQUIDITY_PERCENT, '25')} width="20%">
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment