mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Updates (#192)
* userAvatar * Avatar background * Changes * Removing unused dependencies * Count Bag small and for bigger numbers * decresed bundle size
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { FC, useState, useMemo, useRef, useEffect } from 'react'
|
||||
import { getRandomPairOfColors } from '@lib/colors'
|
||||
import { FC, useRef, useEffect } from 'react'
|
||||
import { useUserAvatar } from '@lib/hooks/useUserAvatar'
|
||||
|
||||
interface Props {
|
||||
className?: string
|
||||
@@ -7,18 +7,13 @@ interface Props {
|
||||
}
|
||||
|
||||
const Avatar: FC<Props> = ({}) => {
|
||||
const [bg] = useState(useMemo(() => getRandomPairOfColors, []))
|
||||
let ref = useRef() as React.MutableRefObject<HTMLInputElement>
|
||||
|
||||
useEffect(() => {
|
||||
if (ref && ref.current) {
|
||||
ref.current.style.backgroundImage = `linear-gradient(140deg, ${bg[0]}, ${bg[1]} 100%)`
|
||||
}
|
||||
}, [bg])
|
||||
let { userAvatar } = useUserAvatar()
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
style={{ backgroundImage: userAvatar }}
|
||||
className="inline-block h-8 w-8 rounded-full border-2 border-primary hover:border-secondary focus:border-secondary transition linear-out duration-150"
|
||||
>
|
||||
{/* Add an image - We're generating a gradient as placeholder <img></img> */}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
@apply outline-none shadow-outline-2;
|
||||
@apply outline-none shadow-outline-normal;
|
||||
}
|
||||
|
||||
.iconContainer {
|
||||
|
@@ -24,7 +24,11 @@
|
||||
}
|
||||
|
||||
.bagCount {
|
||||
@apply border border-accents-1 bg-secondary text-secondary h-4 w-4 absolute rounded-full right-3 top-3 flex items-center justify-center font-bold text-xs;
|
||||
@apply border border-accents-1 bg-secondary text-secondary absolute rounded-full right-3 top-3 flex items-center justify-center font-bold text-xs;
|
||||
padding-left: 2.5px;
|
||||
padding-right: 2.5px;
|
||||
min-width: 1.25rem;
|
||||
min-height: 1.25rem;
|
||||
}
|
||||
|
||||
.avatarButton {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
.leftControl:hover,
|
||||
.rightControl:hover {
|
||||
@apply outline-none shadow-outline-blue;
|
||||
@apply outline-none shadow-outline-normal;
|
||||
}
|
||||
|
||||
.leftControl {
|
||||
@@ -70,7 +70,7 @@
|
||||
}
|
||||
|
||||
.positionIndicator:focus .dot {
|
||||
@apply shadow-outline-blue;
|
||||
@apply shadow-outline-normal;
|
||||
}
|
||||
|
||||
.positionIndicatorActive .dot {
|
||||
|
@@ -7,7 +7,7 @@
|
||||
}
|
||||
|
||||
.root:focus {
|
||||
@apply shadow-outline outline-none;
|
||||
@apply shadow-outline-normal outline-none;
|
||||
}
|
||||
|
||||
.root[data-active] {
|
||||
|
@@ -3,5 +3,5 @@
|
||||
}
|
||||
|
||||
.root:focus {
|
||||
@apply outline-none shadow-outline-gray;
|
||||
@apply outline-none shadow-outline-normal;
|
||||
}
|
||||
|
@@ -52,6 +52,10 @@ type Action =
|
||||
type: 'SET_MODAL_VIEW'
|
||||
view: MODAL_VIEWS
|
||||
}
|
||||
| {
|
||||
type: 'SET_USER_AVATAR'
|
||||
value: string
|
||||
}
|
||||
|
||||
type MODAL_VIEWS = 'SIGNUP_VIEW' | 'LOGIN_VIEW' | 'FORGOT_VIEW'
|
||||
type ToastText = string
|
||||
@@ -123,6 +127,12 @@ function uiReducer(state: State, action: Action) {
|
||||
toastText: action.text,
|
||||
}
|
||||
}
|
||||
case 'SET_USER_AVATAR': {
|
||||
return {
|
||||
...state,
|
||||
userAvatar: action.value,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +157,8 @@ export const UIProvider: FC = (props) => {
|
||||
const openToast = () => dispatch({ type: 'OPEN_TOAST' })
|
||||
const closeToast = () => dispatch({ type: 'CLOSE_TOAST' })
|
||||
|
||||
const setUserAvatar = (value: string) => dispatch({ type: 'SET_USER_AVATAR', value })
|
||||
|
||||
const setModalView = (view: MODAL_VIEWS) =>
|
||||
dispatch({ type: 'SET_MODAL_VIEW', view })
|
||||
|
||||
@@ -164,6 +176,7 @@ export const UIProvider: FC = (props) => {
|
||||
setModalView,
|
||||
openToast,
|
||||
closeToast,
|
||||
setUserAvatar
|
||||
}),
|
||||
[state]
|
||||
)
|
||||
|
Reference in New Issue
Block a user