From 5c69eac83cfba1ce062a2d26454436e31b6cee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateus=20Felipe=20Gon=C3=A7alves?= Date: Fri, 18 Aug 2023 14:01:08 -0300 Subject: [PATCH] feat(ui): create "save-combo" button --- src/app/page.tsx | 6 +- src/components/save-combo-button/index.tsx | 71 ++++++++++++++++++++++ src/components/save-combo-button/styles.ts | 20 ++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/components/save-combo-button/index.tsx create mode 100644 src/components/save-combo-button/styles.ts diff --git a/src/app/page.tsx b/src/app/page.tsx index 605e50c0..46268d4c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -7,6 +7,7 @@ import { SoundButton } from '@/components/sound' import { ClearButton } from '@/components/clear-button' import { Footer } from '@/components/footer' import { useThemeStore } from '@/stores/theme-store' +import { SaveComboButton } from '@/components/save-combo-button' import { sounds } from '@/sounds' import { container } from './styles' @@ -18,8 +19,9 @@ export default function Home() {
-
-
+
+
+
diff --git a/src/components/save-combo-button/index.tsx b/src/components/save-combo-button/index.tsx new file mode 100644 index 00000000..0513f466 --- /dev/null +++ b/src/components/save-combo-button/index.tsx @@ -0,0 +1,71 @@ +import { useState } from 'react' +import { faker } from '@faker-js/faker' + +import { useComboStore } from '@/stores/combo-store' +import { useSoundsStateStore } from '@/stores/sounds-state-store' +import { useThemeStore } from '@/stores/theme-store' + +import { actionButton } from '@/shared/styles/action-button' +import { input } from './styles' +import { FiCheck } from 'react-icons/fi' + +export function SaveComboButton() { + const sounds = useSoundsStateStore(state => state.sounds) + const theme = useThemeStore(state => state.theme) + const saveCombo = useComboStore(state => state.saveCombo) + + const [comboName, setComboName] = useState('') + const [showSuccess, setShowSuccess] = useState(false) + + function save() { + if (!comboName) return + if (!sounds.some(sound => sound.active)) return + + const activeSounds = sounds.filter(sound => sound.active) + + saveCombo({ + id: faker.string.alphanumeric({ casing: 'lower', length: 6 }), + name: comboName, + sounds: activeSounds + }) + + setComboName('') + setShowSuccess(true) + + setTimeout(() => setShowSuccess(false), 2000) + } + + const disabled = showSuccess || !sounds.some(sound => sound.active) + + return ( +
+ {sounds.some(sound => sound.active) && ( + setComboName(e.target.value)} + className={input({ theme })} + /> + )} + +
+ ) +} diff --git a/src/components/save-combo-button/styles.ts b/src/components/save-combo-button/styles.ts new file mode 100644 index 00000000..cc5949af --- /dev/null +++ b/src/components/save-combo-button/styles.ts @@ -0,0 +1,20 @@ +import { tv } from 'tailwind-variants' + +export const input = tv({ + base: /*tw:*/ 'form-input rounded-xl text-white bg-white/5 px-2 py-0 border-none focus:ring-0 leading-none tracking-wider duration-300 w-32 text-center animate-show-input placeholder:text-sm opacity-30 hover:opacity-100 focus:opacity-100', + variants: { + theme: { + transition: /*tw:*/ '', + dark: /*tw:*/ 'text-dark-foreground placeholder:text-dark-foreground/60 bg-dark-foreground/5', + light: + /*tw:*/ 'text-light-foreground placeholder:text-light-foreground/60 bg-light-foreground/5', + 'blue-room': + /*tw:*/ 'text-blue-room placeholder:text-blue-room/60 bg-blue-room/5', + train: /*tw:*/ 'text-train placeholder:text-train/60 bg-train/5', + waterfall: + /*tw:*/ 'text-waterfall placeholder:text-waterfall/60 bg-waterfall/5', + 'camping-fire': + /*tw:*/ 'text-camping-fire placeholder:text-camping-fire/60 bg-camping-fire/5' + } + } +})