Skip to content

Commit

Permalink
adds floating placeholder to select field
Browse files Browse the repository at this point in the history
  • Loading branch information
land-cap committed Mar 20, 2024
1 parent 0e58f89 commit e031dee
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,12 @@ export const VerseLabel = ({ verseNumber }: { verseNumber: ReactNode }) => {
export const Quote = ({ children }: { children: ReactNode }) => {
const font = useAtomValue(fontAtom)

const fontFamily = font !== 'sans' ? font : 'mono'

return (
<span
data-component="Quote"
className={css({
display: 'block',
fontFamily,
fontFamily: font,
textAlign: 'left',
})}
>
Expand All @@ -177,7 +175,7 @@ export const FancyAside = ({ children }: { children: ReactNode }) => {
data-component="FancyAside"
className={css({
color: 'fg.subtle',
fontFamily: font === 'sans' ? 'mono' : undefined,
fontFamily: font,
})}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const viewport = (): Viewport => {
themeColor: [
{
media: '(prefers-color-scheme: light)',
color: isSepiaTheme ? token('colors.sepia.100') : token('colors.white'),
color: isSepiaTheme ? token('colors.sepia.50') : token('colors.white'),
},
{
media: '(prefers-color-scheme: dark)',
Expand Down
10 changes: 7 additions & 3 deletions src/organisms/BottomToolbar/PreferencesMenu/FontField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ export const FontField = () => {
<SelectField.Container>
<FontMenuRoot />
<SelectField.Button
label={
<FontPreview font={font} lineHeight="1">
Font
</FontPreview>
}
placeholder="Font"
onClick={(e) => {
e.stopPropagation()
setIsPreferencesMenuSuspended(true)
setTimeout(() => setShowFontMenu(true), 150)
}}
>
<FontPreview font={font}>Font</FontPreview>
</SelectField.Button>
/>
</SelectField.Container>
)
}
41 changes: 31 additions & 10 deletions src/organisms/BottomToolbar/PreferencesMenu/SelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ButtonHTMLAttributes, type DetailedHTMLProps } from 'react'
import { type MouseEventHandler, type ReactNode } from 'react'
import { css, cx } from 'styled-system/css'
import { styled } from 'styled-system/jsx'
import { Caption, Flex, styled } from 'styled-system/jsx'
import { flex, square } from 'styled-system/patterns'
import { button } from 'styled-system/recipes'

Expand All @@ -18,27 +18,48 @@ const Label = styled('label', {
})

const Button = ({
children,
...props
}: DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>) => (
label,
placeholder,
onClick,
}: {
label: ReactNode
placeholder?: string
onClick?: MouseEventHandler<HTMLButtonElement>
}) => (
<button
className={cx(
'group',
button({ size: 'md', border: true }),
css({
pos: 'relative',
w: 'full',
gap: '4',
justifyContent: 'space-between',
alignItems: 'center',
fontWeight: 'regular',
pr: '0',
_active: { bg: 'none' },
_canHover: { _hover: { bg: 'none' } },
}),
)}
{...props}
onClick={onClick}
>
{children}
<Flex direction="column" gap="1" py="0.5">
{placeholder && (
<Caption
pos="absolute"
top="0"
left="2"
transform="translateY(-50%)"
px="2"
bg="bg.canvas"
_groupHover={{ color: 'fg' }}
>
{placeholder}
</Caption>
)}
{label}
</Flex>
<styled.center className={square({ size: '10' })}>
<Icon code="&#xe409;" size={6} />
</styled.center>
Expand Down
15 changes: 10 additions & 5 deletions src/organisms/BottomToolbar/PreferencesMenu/ThemeField.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useSetAtom } from 'jotai'
import { useAtomValue, useSetAtom } from 'jotai'

import { isPreferencesMenuSuspendedAtom, showThemeMenuAtom } from '~/state'
import {
isPreferencesMenuSuspendedAtom,
showThemeMenuAtom,
themeAtom,
} from '~/state'

import { SelectField } from './SelectField'
import { ThemeMenuRoot } from './ThemeMenu'
Expand All @@ -10,19 +14,20 @@ export const ThemeField = () => {
const setIsPreferencesMenuSuspended = useSetAtom(
isPreferencesMenuSuspendedAtom,
)
const theme = useAtomValue(themeAtom)

return (
<SelectField.Container>
<ThemeMenuRoot />
<SelectField.Button
label={theme}
placeholder="Theme"
onClick={(e) => {
e.stopPropagation()
setIsPreferencesMenuSuspended(true)
setTimeout(() => setShowThemeMenu(true), 150)
}}
>
Theme
</SelectField.Button>
/>
</SelectField.Container>
)
}

0 comments on commit e031dee

Please sign in to comment.