This repository was archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cannot edit a wish with votes (#80)
- Loading branch information
Showing
20 changed files
with
376 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import { HTMLAttributes } from "react"; | ||
import { HTMLAttributes, HTMLProps } from "react"; | ||
import { Except } from "type-fest"; | ||
|
||
export interface IconButtonProps extends HTMLAttributes<HTMLButtonElement> {} | ||
export interface IconButtonProps | ||
extends HTMLAttributes<HTMLButtonElement>, | ||
Except<HTMLProps<HTMLButtonElement>, "as" | "type"> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface StyledInputWrapperProps { | ||
focused?: boolean; | ||
fullWidth?: boolean; | ||
disabled?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { Wish } from "@/types/backend-api"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
|
||
export type UpdateCallback = (previousWish: Wish) => Partial<Wish>; | ||
|
||
export interface WishlistState { | ||
wishes: Wish[]; | ||
error: string; | ||
setError: Dispatch<SetStateAction<string>>; | ||
add(wish: Wish): void; | ||
update(id: number, callback: UpdateCallback): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Icon from "@/atoms/icon"; | ||
import { useTranslation } from "next-i18next"; | ||
import React, { FC, useEffect } from "react"; | ||
import { StyledSnackbar, StyledSnackbarButton, StyledSnackbarMessage } from "./styled"; | ||
import { SnackbarProps } from "./types"; | ||
|
||
const Snackbar: FC<SnackbarProps> = ({ | ||
children, | ||
id, | ||
level = "default", | ||
autoClose = 6000, | ||
onClose, | ||
fixed, | ||
...props | ||
}) => { | ||
const { t } = useTranslation(["common"]); | ||
useEffect(() => { | ||
if (onClose && autoClose > 0) { | ||
const timer = setTimeout(() => { | ||
onClose(); | ||
}, autoClose); | ||
return () => { | ||
onClose(); | ||
clearTimeout(timer); | ||
}; | ||
} | ||
|
||
return () => { | ||
/**/ | ||
}; | ||
}, [onClose, autoClose]); | ||
return ( | ||
<StyledSnackbar | ||
{...props} | ||
fixed={fixed} | ||
level={level} | ||
role="alertdialog" | ||
aria-describedby={id} | ||
> | ||
<StyledSnackbarMessage id={id}>{children}</StyledSnackbarMessage> | ||
{onClose && ( | ||
<StyledSnackbarButton autoFocus aria-label={t("common:close")} onClick={onClose}> | ||
<Icon icon="close" /> | ||
</StyledSnackbarButton> | ||
)} | ||
</StyledSnackbar> | ||
); | ||
}; | ||
|
||
export default Snackbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import IconButton from "@/atoms/icon-button"; | ||
import { shadows } from "@/ions/theme"; | ||
import { pxToRem } from "@/ions/utils/unit"; | ||
import { css } from "@emotion/react"; | ||
import styled from "@emotion/styled"; | ||
import { SnackbarBackgrounds, SnackbarColors, StyledSnackbarProps } from "./types"; | ||
|
||
export const StyledSnackbar = styled.div<StyledSnackbarProps>` | ||
display: grid; | ||
grid-template-columns: 1fr auto; | ||
width: ${pxToRem(600)}; | ||
${({ theme, level, fixed }) => css` | ||
${fixed && | ||
css` | ||
position: fixed; | ||
z-index: 5; | ||
bottom: 0; | ||
left: 50%; | ||
transform: translateX(-50%); | ||
box-shadow: ${shadows.l}; | ||
`}; | ||
grid-gap: ${pxToRem(theme.spaces.xs)}; | ||
max-width: ${fixed ? `calc(100% - ${pxToRem(2 * theme.spaces.l)})` : "100%"}; | ||
margin: ${pxToRem(theme.spaces.m)} 0; | ||
padding: ${pxToRem(theme.spaces.s)} ${pxToRem(theme.spaces.m)}; | ||
border-radius: ${theme.shapes.s}; | ||
background: ${theme.palette[backgroundColors[level]]}; | ||
color: ${colors[level]}; | ||
`}; | ||
`; | ||
|
||
const backgroundColors: SnackbarBackgrounds = { | ||
default: "dark", | ||
warning: "yellow", | ||
info: "blue", | ||
error: "red", | ||
}; | ||
|
||
const colors: SnackbarColors = { | ||
default: "white", | ||
warning: "black", | ||
info: "black", | ||
error: "white", | ||
}; | ||
|
||
export const StyledSnackbarButton = styled(IconButton)` | ||
align-self: center; | ||
${({ theme }) => css` | ||
margin: ${pxToRem(-theme.spaces.s)} ${pxToRem(-theme.spaces.xs)}; | ||
`}; | ||
`; | ||
|
||
export const StyledSnackbarMessage = styled.div``; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Palette } from "@/types/theme"; | ||
|
||
export type SnackbarLevel = "warning" | "info" | "error" | "default"; | ||
|
||
export type SnackbarBackgrounds = Record<SnackbarLevel, keyof Palette>; | ||
|
||
export type SnackbarColor = "black" | "white"; | ||
|
||
export type SnackbarColors = Record<SnackbarLevel, SnackbarColor>; | ||
|
||
export interface StyledSnackbarProps { | ||
level?: SnackbarLevel; | ||
fixed?: boolean; | ||
} | ||
|
||
export interface SnackbarProps extends StyledSnackbarProps { | ||
autoClose?: number; | ||
id: string; | ||
onClose?(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
47e17ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: