Skip to content

Commit

Permalink
feat(ui): improve QuantityInput spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Apr 5, 2024
1 parent 07127f1 commit e0a9b51
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/components/AnimatedNumber/AnimatedNumber.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React, { useEffect, useState } from 'react'
import { tween } from 'shifty'
import { func, number } from 'prop-types'
import { func, number, object } from 'prop-types'

import { Span } from '../Elements'
import './AnimatedNumber.sass'

const defaultFormatter = number => `${number}`

const AnimatedNumber = ({ number, formatter = defaultFormatter }) => {
const AnimatedNumber = ({
number,
animatedNumberSx,
formatter = defaultFormatter,
}) => {
const [displayedNumber, setDisplayedNumber] = useState(number)
const [previousNumber, setPreviousNumber] = useState(number)
const [currentTweenable, setCurrentTweenable] = useState()
Expand Down Expand Up @@ -42,12 +47,17 @@ const AnimatedNumber = ({ number, formatter = defaultFormatter }) => {
}
}
}, [currentTweenable, number, previousNumber])
return <span className="AnimatedNumber">{formatter(displayedNumber)}</span>
return (
<Span className="AnimatedNumber" sx={animatedNumberSx}>
{formatter(displayedNumber)}
</Span>
)
}

AnimatedNumber.propTypes = {
formatter: func,
number: number.isRequired,
animatedNumberSx: object,
}

export default AnimatedNumber
3 changes: 3 additions & 0 deletions src/components/Elements/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import styled from '@mui/material/styles/styled'

export const Span = styled('span')({})
6 changes: 5 additions & 1 deletion src/components/QuantityInput/QuantityInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ const QuantityInput = ({
<span className="quantity">
/{' '}
<AnimatedNumber
{...{ number: maxQuantity, formatter: integerString }}
{...{
number: maxQuantity,
formatter: integerString,
animatedNumberSx: { pl: 1 },
}}
/>
</span>
<div className="number-nudger-container">
Expand Down
2 changes: 1 addition & 1 deletion src/components/QuantityInput/QuantityInput.sass
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
margin-left: 1em

.quantity
line-height: 2.8em
line-height: 2.3em

.MuiInput-root
max-width: 75px
Expand Down

0 comments on commit e0a9b51

Please sign in to comment.