===== Claude Code karpathy, with the rule, run 1 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..6ef3bad 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. Convert an iterable of items into a human-readable string with commas and 'and'. @@ -22,9 +22,12 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word joining the last two items. Defaults to "and". Returns: str: A string with commas and 'and' in the right places. @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..7870543 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,9 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code karpathy, with the rule, run 2 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..6ef3bad 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. Convert an iterable of items into a human-readable string with commas and 'and'. @@ -22,9 +22,12 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word joining the last two items. Defaults to "and". Returns: str: A string with commas and 'and' in the right places. @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..7870543 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,9 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code karpathy, with the rule, run 3 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..6ef3bad 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. Convert an iterable of items into a human-readable string with commas and 'and'. @@ -22,9 +22,12 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word joining the last two items. Defaults to "and". Returns: str: A string with commas and 'and' in the right places. @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..7870543 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,9 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code karpathy, without the rule, run 1 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..8c3c853 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,10 +10,11 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with commas and a + conjunction ('and' by default). Examples: >>> natural_list(["one", "two", "three"]) @@ -22,12 +23,15 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word used before the last item. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the conjunction in the right places. """ item_list = [str(item) for item in items] if not item_list: @@ -35,6 +39,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..9fdabcd 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,10 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), + ([[], "or"], ""), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code karpathy, without the rule, run 2 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..97424eb 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,10 +10,10 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with commas and a conjunction. Examples: >>> natural_list(["one", "two", "three"]) @@ -22,12 +22,15 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word joining the last two items. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the conjunction in the right places. """ item_list = [str(item) for item in items] if not item_list: @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..9fdabcd 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,10 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), + ([[], "or"], ""), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code karpathy, without the rule, run 3 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..bdfa3ca 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. Convert an iterable of items into a human-readable string with commas and 'and'. @@ -22,12 +22,15 @@ def natural_list(items: Iterable[Any]) -> str: 'one and two' >>> natural_list(["one"]) 'one' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' Args: items (Iterable): An iterable of items. + conjunction (str): The word joining the last two items. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the conjunction in the right places. """ item_list = [str(item) for item in items] if not item_list: @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" diff --git a/tests/test_lists.py b/tests/test_lists.py index 9b3c1b7..9fdabcd 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -25,6 +25,10 @@ import humanize ([{"one": 1, "two": 2}.keys()], "one and two"), ([(x for x in ["one", "two", "three"])], "one, two and three"), ([range(1, 4)], "1, 2 and 3"), + ([["one", "two", "three"], "or"], "one, two or three"), + ([["one", "two"], "or"], "one or two"), + ([["one"], "or"], "one"), + ([[], "or"], ""), ], ) def test_natural_list(test_args: Iterable[Any], expected: str) -> None: ===== Claude Code screens, with the rule, run 1 diff --git a/src/App.css b/src/App.css index f90339d..710e6d4 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,97 @@ border-right-color: var(--border); } } + +#settings { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + justify-content: center; + gap: 24px 32px; + padding: 32px; + border-top: 1px solid var(--border); + + h2 { + flex-basis: 100%; + margin: 0; + } + + @media (max-width: 1024px) { + padding: 24px 20px; + gap: 20px; + } +} + +.choice-group { + border: none; + margin: 0; + padding: 0; + + legend { + padding: 0; + margin-bottom: 8px; + font-size: 14px; + color: var(--text-h); + } +} + +.segments { + display: inline-flex; + padding: 3px; + gap: 3px; + border-radius: 8px; + background: var(--social-bg); + border: 1px solid var(--border); + + label { + position: relative; + padding: 4px 14px; + border-radius: 5px; + font-size: 16px; + text-transform: capitalize; + cursor: pointer; + transition: background 0.2s, color 0.2s; + + &:hover { + color: var(--text-h); + } + &:has(:checked) { + color: var(--accent); + background: var(--accent-bg); + } + &:has(:focus-visible) { + outline: 2px solid var(--accent); + outline-offset: 1px; + } + } + + input { + position: absolute; + opacity: 0; + pointer-events: none; + } +} + +.reset { + font: inherit; + font-size: 16px; + padding: 5px 14px; + border-radius: 8px; + color: var(--text-h); + background: transparent; + border: 1px solid var(--border); + cursor: pointer; + transition: border-color 0.2s; + + &:hover:not(:disabled) { + border-color: var(--accent-border); + } + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + &:disabled { + opacity: 0.5; + cursor: default; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..4ddabfe 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,9 +3,19 @@ import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' import './App.css' +import { SettingsPanel } from './SettingsPanel' +import { + STEPS, + THEMES, + useApplyTheme, + useStoredChoice, +} from './settings' function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useStoredChoice('theme', THEMES, 'system') + const [step, setStep] = useStoredChoice('step', STEPS, 1) + useApplyTheme(theme) return ( <> @@ -24,12 +34,21 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + setCount(0)} + resetDisabled={count === 0} + /> + diff --git a/src/SettingsPanel.tsx b/src/SettingsPanel.tsx new file mode 100644 index 0000000..c0636a8 --- /dev/null +++ b/src/SettingsPanel.tsx @@ -0,0 +1,83 @@ +import { STEPS, THEMES, type Step, type Theme } from './settings' + +type Props = { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void + resetDisabled: boolean +} + +type ChoiceGroupProps = { + legend: string + name: string + options: readonly T[] + value: T + onChange: (value: T) => void +} + +function ChoiceGroup({ + legend, + name, + options, + value, + onChange, +}: ChoiceGroupProps) { + return ( + + {legend} + + {options.map((option) => ( + + onChange(option)} + /> + {option} + + ))} + + + ) +} + +export function SettingsPanel({ + theme, + onThemeChange, + step, + onStepChange, + onReset, + resetDisabled, +}: Props) { + return ( + + Settings + + + + Reset count + + + ) +} diff --git a/src/index.css b/src/index.css index 5fb3313..4ba91c3 100644 --- a/src/index.css +++ b/src/index.css @@ -1,13 +1,16 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark( + rgba(170, 59, 255, 0.5), + rgba(192, 132, 252, 0.5) + ); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; @@ -30,23 +33,32 @@ } } +/* Theme override set by the settings panel; absent means "system". */ +:root[data-theme='light'] { + color-scheme: light; +} +:root[data-theme='dark'] { + color-scheme: dark; +} + +/* Values that light-dark() can't express (shadows, filters). */ +:root[data-theme='dark'] { + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; + + #social .button-icon { + filter: invert(1) brightness(2); + } +} + @media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); + :root:not([data-theme='light']) { --shadow: rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } - #social .button-icon { - filter: invert(1) brightness(2); + #social .button-icon { + filter: invert(1) brightness(2); + } } } diff --git a/src/settings.ts b/src/settings.ts new file mode 100644 index 0000000..08b8a73 --- /dev/null +++ b/src/settings.ts @@ -0,0 +1,42 @@ +import { useEffect, useLayoutEffect, useState } from 'react' + +export const THEMES = ['light', 'dark', 'system'] as const +export type Theme = (typeof THEMES)[number] + +export const STEPS = [1, 5, 10] as const +export type Step = (typeof STEPS)[number] + +/** useState backed by localStorage; falls back when the stored value isn't allowed. */ +export function useStoredChoice( + key: string, + allowed: readonly T[], + fallback: T, +) { + const [value, setValue] = useState(() => { + try { + const raw = localStorage.getItem(key) + return allowed.find((option) => String(option) === raw) ?? fallback + } catch { + return fallback + } + }) + + useEffect(() => { + try { + localStorage.setItem(key, String(value)) + } catch { + // Storage unavailable (private mode, quota): keep in-memory value only. + } + }, [key, value]) + + return [value, setValue] as const +} + +/** Reflects the theme on ; "system" removes the override. */ +export function useApplyTheme(theme: Theme) { + useLayoutEffect(() => { + const root = document.documentElement + if (theme === 'system') delete root.dataset.theme + else root.dataset.theme = theme + }, [theme]) +} ===== Claude Code screens, with the rule, run 2 diff --git a/index.html b/index.html index 3d38e14..f2378d2 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,13 @@ + Vite + React + TS diff --git a/src/App.css b/src/App.css index f90339d..443e69e 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,76 @@ border-right-color: var(--border); } } + +.settings { + display: flex; + flex-wrap: wrap; + gap: 16px 32px; + align-items: end; + justify-content: center; + + fieldset { + display: flex; + gap: 4px; + margin: 0; + padding: 0; + border: 0; + } + + legend { + width: 100%; + margin-bottom: 6px; + font-size: 14px; + color: var(--text); + } + + label { + position: relative; + padding: 5px 12px; + border-radius: 5px; + font-size: 16px; + color: var(--text-h); + background: var(--social-bg); + border: 2px solid transparent; + cursor: pointer; + transition: border-color 0.3s; + + &:hover { + border-color: var(--accent-border); + } + &:has(:checked) { + color: var(--accent); + background: var(--accent-bg); + } + &:has(:focus-visible) { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } + + input { + position: absolute; + opacity: 0; + pointer-events: none; + } + + .reset { + font: inherit; + font-size: 16px; + padding: 5px 12px; + border-radius: 5px; + color: var(--text-h); + background: transparent; + border: 2px solid var(--border); + cursor: pointer; + transition: border-color 0.3s; + + &:hover { + border-color: var(--accent-border); + } + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..2aa73eb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,10 +2,14 @@ import { useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' +import Settings from './Settings' +import { useStep, useTheme } from './useSettings' import './App.css' function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useTheme() + const [step, setStep] = useStep() return ( <> @@ -24,10 +28,17 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + setCount(0)} + /> diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..7409a47 --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,57 @@ +import { STEPS, THEMES, type Step, type Theme } from './useSettings' + +type SettingsProps = { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void +} + +function Settings({ + theme, + onThemeChange, + step, + onStepChange, + onReset, +}: SettingsProps) { + return ( + + + Theme + {THEMES.map((value) => ( + + onThemeChange(value)} + /> + {value[0].toUpperCase() + value.slice(1)} + + ))} + + + Step + {STEPS.map((value) => ( + + onStepChange(value)} + /> + {value} + + ))} + + + Reset + + + ) +} + +export default Settings diff --git a/src/index.css b/src/index.css index 5fb3313..43da4ca 100644 --- a/src/index.css +++ b/src/index.css @@ -30,8 +30,25 @@ } } +/* Dark palette: applies when chosen explicitly, or when following a dark system. */ +:root[data-theme='dark'] { + color-scheme: dark; + --text: #9ca3af; + --text-h: #f3f4f6; + --bg: #16171d; + --border: #2e303a; + --code-bg: #1f2028; + --accent: #c084fc; + --accent-bg: rgba(192, 132, 252, 0.15); + --accent-border: rgba(192, 132, 252, 0.5); + --social-bg: rgba(47, 48, 58, 0.5); + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; + --icon-filter: invert(1) brightness(2); +} + @media (prefers-color-scheme: dark) { - :root { + :root:not([data-theme='light']) { --text: #9ca3af; --text-h: #f3f4f6; --bg: #16171d; @@ -43,11 +60,16 @@ --social-bg: rgba(47, 48, 58, 0.5); --shadow: rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; + --icon-filter: invert(1) brightness(2); } +} - #social .button-icon { - filter: invert(1) brightness(2); - } +:root[data-theme='light'] { + color-scheme: light; +} + +#social .button-icon { + filter: var(--icon-filter, none); } #root { diff --git a/src/useSettings.ts b/src/useSettings.ts new file mode 100644 index 0000000..af5c0f8 --- /dev/null +++ b/src/useSettings.ts @@ -0,0 +1,53 @@ +import { useEffect, useState } from 'react' + +export const THEMES = ['light', 'dark', 'system'] as const +export type Theme = (typeof THEMES)[number] + +export const STEPS = [1, 5, 10] as const +export type Step = (typeof STEPS)[number] + +// Keep in sync with the inline script in index.html, which applies the +// stored theme before first paint. +const THEME_KEY = 'theme' +const STEP_KEY = 'step' + +function read(key: string, allowed: readonly T[], fallback: T): T { + try { + const raw = localStorage.getItem(key) + const match = allowed.find((value) => String(value) === raw) + return match ?? fallback + } catch { + return fallback + } +} + +function write(key: string, value: string) { + try { + localStorage.setItem(key, value) + } catch { + // Storage unavailable (private mode, quota); settings still work for the session. + } +} + +export function useTheme() { + const [theme, setTheme] = useState(() => + read(THEME_KEY, THEMES, 'system'), + ) + + useEffect(() => { + const root = document.documentElement + if (theme === 'system') root.removeAttribute('data-theme') + else root.dataset.theme = theme + write(THEME_KEY, theme) + }, [theme]) + + return [theme, setTheme] as const +} + +export function useStep() { + const [step, setStep] = useState(() => read(STEP_KEY, STEPS, 1)) + + useEffect(() => write(STEP_KEY, String(step)), [step]) + + return [step, setStep] as const +} ===== Claude Code screens, with the rule, run 3 diff --git a/index.html b/index.html index 3d38e14..a0c7411 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,13 @@ Vite + React + TS + diff --git a/src/App.css b/src/App.css index f90339d..50a58a1 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,88 @@ border-right-color: var(--border); } } + +#settings { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + justify-content: center; + gap: 16px 24px; + padding: 20px 24px; + border: 1px solid var(--border); + border-radius: 8px; + + h2 { + flex-basis: 100%; + margin: 0; + font-size: 18px; + text-align: left; + } +} + +.segmented { + border: none; + margin: 0; + padding: 0; + text-align: left; + + legend { + padding: 0; + margin-bottom: 6px; + font-size: 14px; + } + + div { + display: flex; + border: 1px solid var(--border); + border-radius: 6px; + overflow: hidden; + } + + label { + position: relative; + padding: 4px 12px; + font-size: 15px; + cursor: pointer; + color: var(--text-h); + + & + label { + border-left: 1px solid var(--border); + } + + &:has(:checked) { + color: var(--accent); + background: var(--accent-bg); + } + + &:has(:focus-visible) { + outline: 2px solid var(--accent); + outline-offset: -2px; + } + } + + input { + position: absolute; + opacity: 0; + pointer-events: none; + } +} + +.reset { + font: inherit; + font-size: 15px; + padding: 4px 12px; + border-radius: 6px; + border: 1px solid var(--border); + background: transparent; + color: var(--text-h); + cursor: pointer; + + &:hover { + border-color: var(--accent-border); + } + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..900dc46 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,9 +3,13 @@ import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' import './App.css' +import { Settings } from './Settings' +import { useStep, useTheme } from './settings' function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useTheme() + const [step, setStep] = useStep() return ( <> @@ -24,10 +28,17 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + setCount(0)} + /> diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..4045de6 --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,75 @@ +import { STEPS, THEMES, type Step, type Theme } from './settings' + +type Props = { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void +} + +function Segmented({ + legend, + name, + options, + value, + onChange, +}: { + legend: string + name: string + options: readonly T[] + value: T + onChange: (value: T) => void +}) { + return ( + + {legend} + + {options.map((option) => ( + + onChange(option)} + /> + {typeof option === 'string' + ? option[0].toUpperCase() + option.slice(1) + : option} + + ))} + + + ) +} + +export function Settings({ + theme, + onThemeChange, + step, + onStepChange, + onReset, +}: Props) { + return ( + + Settings + + + + Reset count + + + ) +} diff --git a/src/index.css b/src/index.css index 5fb3313..18cd8dd 100644 --- a/src/index.css +++ b/src/index.css @@ -1,15 +1,19 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark( + rgba(170, 59, 255, 0.5), + rgba(192, 132, 252, 0.5) + ); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; + light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4)) 0 10px 15px -3px, + light-dark(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.25)) 0 4px 6px -2px; --sans: system-ui, 'Segoe UI', Roboto, sans-serif; --heading: system-ui, 'Segoe UI', Roboto, sans-serif; @@ -30,22 +34,19 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +/* data-theme is set from the theme setting; absent or "system" follows the OS. */ +:root[data-theme='light'] { + color-scheme: light; +} +:root[data-theme='dark'] { + color-scheme: dark; +} - #social .button-icon { +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} +@media (prefers-color-scheme: dark) { + :root:not([data-theme='light']) #social .button-icon { filter: invert(1) brightness(2); } } diff --git a/src/settings.ts b/src/settings.ts new file mode 100644 index 0000000..23df8a3 --- /dev/null +++ b/src/settings.ts @@ -0,0 +1,46 @@ +import { useEffect, useState } from 'react' + +export const THEMES = ['light', 'dark', 'system'] as const +export type Theme = (typeof THEMES)[number] + +export const STEPS = [1, 5, 10] as const +export type Step = (typeof STEPS)[number] + +// Keep THEME_KEY in sync with the pre-paint script in index.html. +const THEME_KEY = 'theme' +const STEP_KEY = 'step' + +function read(key: string, allowed: readonly T[], fallback: T): T { + try { + const raw = localStorage.getItem(key) + const value = allowed.find((v) => String(v) === raw) + return value ?? fallback + } catch { + return fallback + } +} + +function write(key: string, value: string) { + try { + localStorage.setItem(key, value) + } catch { + // Storage unavailable (private mode, quota): setting still applies for this session. + } +} + +export function useTheme() { + const [theme, setTheme] = useState(() => + read(THEME_KEY, THEMES, 'system'), + ) + useEffect(() => { + document.documentElement.dataset.theme = theme + write(THEME_KEY, theme) + }, [theme]) + return [theme, setTheme] as const +} + +export function useStep() { + const [step, setStep] = useState(() => read(STEP_KEY, STEPS, 1)) + useEffect(() => write(STEP_KEY, String(step)), [step]) + return [step, setStep] as const +} ===== Claude Code screens, without the rule, run 1 diff --git a/src/App.css b/src/App.css index f90339d..e35fc40 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,49 @@ border-right-color: var(--border); } } + +#settings { + border-top: 1px solid var(--border); + padding: 32px; + display: flex; + flex-direction: column; + align-items: center; + gap: 16px; + + @media (max-width: 1024px) { + padding: 24px 20px; + } + + fieldset { + border: 1px solid var(--border); + border-radius: 6px; + padding: 8px 16px 12px; + margin: 0; + display: flex; + gap: 16px; + justify-content: center; + flex-wrap: wrap; + } + + legend { + color: var(--text-h); + padding: 0 6px; + } + + label { + display: inline-flex; + align-items: center; + gap: 6px; + cursor: pointer; + } + + input { + accent-color: var(--accent); + margin: 0; + } + + .counter { + margin-bottom: 0; + cursor: pointer; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..bccc8f8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,51 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' +import Settings, { STEPS, THEMES, type Step, type Theme } from './Settings' import './App.css' +const THEME_KEY = 'settings.theme' +const STEP_KEY = 'settings.step' + +function readStored(key: string, allowed: readonly T[], fallback: T): T { + try { + const raw = localStorage.getItem(key) + const match = allowed.find((v) => String(v) === raw) + return match ?? fallback + } catch { + return fallback + } +} + +function writeStored(key: string, value: string) { + try { + localStorage.setItem(key, value) + } catch { + // storage unavailable (e.g. private mode) – setting just won't persist + } +} + function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useState(() => + readStored(THEME_KEY, THEMES, 'system'), + ) + const [step, setStep] = useState(() => readStored(STEP_KEY, STEPS, 1)) + + useEffect(() => { + const root = document.documentElement + if (theme === 'system') { + root.removeAttribute('data-theme') + } else { + root.setAttribute('data-theme', theme) + } + writeStored(THEME_KEY, theme) + }, [theme]) + + useEffect(() => { + writeStored(STEP_KEY, String(step)) + }, [step]) return ( <> @@ -24,7 +64,7 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} @@ -32,6 +72,16 @@ function App() { + setCount(0)} + /> + + + diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..77fb700 --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,67 @@ +export type Theme = 'light' | 'dark' | 'system' +export type Step = 1 | 5 | 10 + +export const THEMES: readonly Theme[] = ['light', 'dark', 'system'] +export const STEPS: readonly Step[] = [1, 5, 10] + +interface SettingsProps { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void +} + +const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1) + +function Settings({ + theme, + onThemeChange, + step, + onStepChange, + onReset, +}: SettingsProps) { + return ( + + Settings + + + Theme + {THEMES.map((t) => ( + + onThemeChange(t)} + /> + {capitalize(t)} + + ))} + + + + Step size + {STEPS.map((s) => ( + + onStepChange(s)} + /> + {s} + + ))} + + + + Reset count to 0 + + + ) +} + +export default Settings diff --git a/src/index.css b/src/index.css index 5fb3313..923f11a 100644 --- a/src/index.css +++ b/src/index.css @@ -30,8 +30,33 @@ } } +/* Explicit theme choice (set by the settings panel via data-theme on ) */ +:root[data-theme='light'] { + color-scheme: light; +} + +:root[data-theme='dark'] { + color-scheme: dark; + --text: #9ca3af; + --text-h: #f3f4f6; + --bg: #16171d; + --border: #2e303a; + --code-bg: #1f2028; + --accent: #c084fc; + --accent-bg: rgba(192, 132, 252, 0.15); + --accent-border: rgba(192, 132, 252, 0.5); + --social-bg: rgba(47, 48, 58, 0.5); + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; +} + +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} + +/* "System" theme: follow the OS preference unless light/dark was chosen */ @media (prefers-color-scheme: dark) { - :root { + :root:not([data-theme='light']) { --text: #9ca3af; --text-h: #f3f4f6; --bg: #16171d; @@ -45,7 +70,7 @@ rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; } - #social .button-icon { + :root:not([data-theme='light']) #social .button-icon { filter: invert(1) brightness(2); } } ===== Claude Code screens, without the rule, run 2 diff --git a/src/App.css b/src/App.css index f90339d..aae6829 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,109 @@ border-right-color: var(--border); } } + +#settings { + border-top: 1px solid var(--border); + padding: 32px; + display: flex; + flex-wrap: wrap; + gap: 24px 40px; + align-items: flex-end; + justify-content: center; + + h2 { + flex-basis: 100%; + margin: 0; + } + + fieldset { + border: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 8px; + } + + legend { + padding: 0; + margin-bottom: 8px; + font-size: 14px; + color: var(--text); + } + + @media (max-width: 1024px) { + padding: 24px 20px; + } +} + +.segmented { + display: inline-flex; + border: 1px solid var(--border); + border-radius: 6px; + overflow: hidden; + + label { + position: relative; + cursor: pointer; + } + + label + label span { + border-left: 1px solid var(--border); + } + + input { + position: absolute; + opacity: 0; + inset: 0; + margin: 0; + cursor: pointer; + } + + span { + display: block; + min-width: 2.5em; + padding: 6px 14px; + font-size: 16px; + color: var(--text-h); + transition: background 0.2s; + } + + label:hover span { + background: var(--social-bg); + } + + input:checked + span { + color: var(--accent); + background: var(--accent-bg); + } + + input:focus-visible + span { + outline: 2px solid var(--accent); + outline-offset: -2px; + } +} + +.reset { + font: inherit; + font-size: 16px; + padding: 6px 14px; + border-radius: 6px; + border: 1px solid var(--border); + background: transparent; + color: var(--text-h); + cursor: pointer; + transition: box-shadow 0.3s; + + &:hover:not(:disabled) { + box-shadow: var(--shadow); + } + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + &:disabled { + opacity: 0.5; + cursor: not-allowed; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..3d7f0ce 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,54 @@ -import { useState } from 'react' +import { useLayoutEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' +import Settings, { STEPS, THEMES, type Step, type Theme } from './Settings' import './App.css' +const THEME_KEY = 'settings.theme' +const STEP_KEY = 'settings.step' + +function readStored(key: string, allowed: readonly T[], fallback: T): T { + try { + const raw = localStorage.getItem(key) + const match = allowed.find((v) => String(v) === raw) + return match ?? fallback + } catch { + return fallback + } +} + +function store(key: string, value: string) { + try { + localStorage.setItem(key, value) + } catch { + // Storage unavailable (e.g. private mode); settings just won't persist. + } +} + function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useState(() => + readStored(THEME_KEY, THEMES, 'system'), + ) + const [step, setStep] = useState(() => readStored(STEP_KEY, STEPS, 1)) + + // Apply before paint so a stored theme doesn't flash the wrong colours. + useLayoutEffect(() => { + const root = document.documentElement + if (theme === 'system') root.removeAttribute('data-theme') + else root.dataset.theme = theme + }, [theme]) + + const changeTheme = (next: Theme) => { + setTheme(next) + store(THEME_KEY, next) + } + + const changeStep = (next: Step) => { + setStep(next) + store(STEP_KEY, String(next)) + } return ( <> @@ -24,12 +67,21 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + setCount(0)} + resetDisabled={count === 0} + /> + diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..2811b94 --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,76 @@ +export type Theme = 'light' | 'dark' | 'system' +export type Step = 1 | 5 | 10 + +export const THEMES: readonly Theme[] = ['light', 'dark', 'system'] +export const STEPS: readonly Step[] = [1, 5, 10] + +type SettingsProps = { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void + resetDisabled: boolean +} + +function Settings({ + theme, + onThemeChange, + step, + onStepChange, + onReset, + resetDisabled, +}: SettingsProps) { + return ( + + Settings + + + Theme + + {THEMES.map((t) => ( + + onThemeChange(t)} + /> + {t[0].toUpperCase() + t.slice(1)} + + ))} + + + + + Step size + + {STEPS.map((s) => ( + + onStepChange(s)} + /> + {s} + + ))} + + + + + Reset count to 0 + + + ) +} + +export default Settings diff --git a/src/index.css b/src/index.css index 5fb3313..706f2a0 100644 --- a/src/index.css +++ b/src/index.css @@ -30,8 +30,33 @@ } } +/* Theme setting: data-theme="light" | "dark" forces a palette; no attribute + ("system") follows the OS via prefers-color-scheme below. */ +:root[data-theme='light'] { + color-scheme: light; +} + +:root[data-theme='dark'] { + color-scheme: dark; + --text: #9ca3af; + --text-h: #f3f4f6; + --bg: #16171d; + --border: #2e303a; + --code-bg: #1f2028; + --accent: #c084fc; + --accent-bg: rgba(192, 132, 252, 0.15); + --accent-border: rgba(192, 132, 252, 0.5); + --social-bg: rgba(47, 48, 58, 0.5); + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; +} + +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} + @media (prefers-color-scheme: dark) { - :root { + :root:not([data-theme]) { --text: #9ca3af; --text-h: #f3f4f6; --bg: #16171d; @@ -45,7 +70,7 @@ rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; } - #social .button-icon { + :root:not([data-theme]) #social .button-icon { filter: invert(1) brightness(2); } } ===== Claude Code screens, without the rule, run 3 diff --git a/src/App.css b/src/App.css index f90339d..3a743b5 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,66 @@ border-right-color: var(--border); } } + +.settings { + display: flex; + flex-direction: column; + align-items: center; + gap: 16px; + padding: 20px 28px; + border: 1px solid var(--border); + border-radius: 8px; + text-align: left; + + h2 { + margin: 0; + } + + fieldset { + display: flex; + flex-wrap: wrap; + gap: 16px; + margin: 0; + padding: 8px 12px; + border: 1px solid var(--border); + border-radius: 6px; + } + + legend { + padding: 0 4px; + font-size: 14px; + color: var(--text-h); + } + + label { + display: inline-flex; + align-items: center; + gap: 6px; + font-size: 16px; + cursor: pointer; + } + + input { + accent-color: var(--accent); + margin: 0; + } + + .reset { + font: inherit; + font-size: 16px; + padding: 5px 12px; + border-radius: 5px; + color: var(--text-h); + background: var(--code-bg); + border: 1px solid var(--border); + cursor: pointer; + + &:hover { + border-color: var(--accent-border); + } + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..3e5572f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,35 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' import './App.css' +import Settings, { STEPS, THEMES, type Step, type Theme } from './Settings' + +function loadTheme(): Theme { + const saved = localStorage.getItem('theme') + return THEMES.find((t) => t === saved) ?? 'system' +} + +function loadStep(): Step { + const saved = Number(localStorage.getItem('step')) + return STEPS.find((s) => s === saved) ?? 1 +} function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useState(loadTheme) + const [step, setStep] = useState(loadStep) + + useEffect(() => { + const root = document.documentElement + if (theme === 'system') delete root.dataset.theme + else root.dataset.theme = theme + localStorage.setItem('theme', theme) + }, [theme]) + + useEffect(() => { + localStorage.setItem('step', String(step)) + }, [step]) return ( <> @@ -24,10 +48,17 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + setCount(0)} + /> diff --git a/src/Settings.tsx b/src/Settings.tsx new file mode 100644 index 0000000..5973e1d --- /dev/null +++ b/src/Settings.tsx @@ -0,0 +1,65 @@ +export const THEMES = ['light', 'dark', 'system'] as const +export type Theme = (typeof THEMES)[number] + +export const STEPS = [1, 5, 10] as const +export type Step = (typeof STEPS)[number] + +type SettingsProps = { + theme: Theme + onThemeChange: (theme: Theme) => void + step: Step + onStepChange: (step: Step) => void + onReset: () => void +} + +function Settings({ + theme, + onThemeChange, + step, + onStepChange, + onReset, +}: SettingsProps) { + return ( + + Settings + + + Theme + {THEMES.map((t) => ( + + onThemeChange(t)} + /> + {t[0].toUpperCase() + t.slice(1)} + + ))} + + + + Step size + {STEPS.map((s) => ( + + onStepChange(s)} + /> + {s} + + ))} + + + + Reset count + + + ) +} + +export default Settings diff --git a/src/index.css b/src/index.css index 5fb3313..097fced 100644 --- a/src/index.css +++ b/src/index.css @@ -30,8 +30,33 @@ } } +/* Dark palette: applied when the user picks "dark", or picks "system" + (the default) and the OS prefers dark. */ +:root[data-theme='dark'] { + color-scheme: dark; + --text: #9ca3af; + --text-h: #f3f4f6; + --bg: #16171d; + --border: #2e303a; + --code-bg: #1f2028; + --accent: #c084fc; + --accent-bg: rgba(192, 132, 252, 0.15); + --accent-border: rgba(192, 132, 252, 0.5); + --social-bg: rgba(47, 48, 58, 0.5); + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; +} + +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} + +:root[data-theme='light'] { + color-scheme: light; +} + @media (prefers-color-scheme: dark) { - :root { + :root:not([data-theme='light']):not([data-theme='dark']) { --text: #9ca3af; --text-h: #f3f4f6; --bg: #16171d; @@ -45,7 +70,7 @@ rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; } - #social .button-icon { + :root:not([data-theme='light']):not([data-theme='dark']) #social .button-icon { filter: invert(1) brightness(2); } } ===== Claude Code outdated, with the rule, run 1 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..4bee436 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -36,6 +39,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.debug('Wrote replay file %s', replay_file) + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -44,6 +49,8 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: with open(replay_file, encoding="utf-8") as infile: context: dict[str, Any] = json.load(infile) + logger.debug('Read replay file %s', replay_file) + if 'cookiecutter' not in context: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..6222919 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -96,3 +96,14 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_logs_replay_file( + caplog, mock_ensure_success, template_name, context, replay_test_dir, replay_file +) -> None: + """Test that replay.dump reports which replay file was written.""" + caplog.set_level('DEBUG', logger='cookiecutter.replay') + + replay.dump(replay_test_dir, template_name, context) + + assert f'Wrote replay file {replay_file}' in caplog.messages diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..37f209a 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -52,3 +52,14 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_logs_replay_file( + caplog, template_name, replay_test_dir, replay_file +) -> None: + """Test that replay.load reports which replay file was read.""" + caplog.set_level('DEBUG', logger='cookiecutter.replay') + + replay.load(replay_test_dir, template_name) + + assert f'Read replay file {replay_file}' in caplog.messages ===== Claude Code outdated, with the rule, run 2 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..9f689dd 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -36,6 +39,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.info('Wrote replay file %s', replay_file) + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +53,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + logger.info('Read replay file %s', replay_file) return context diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..87041c5 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -1,6 +1,7 @@ """test_dump.""" import json +import logging import os import pytest @@ -96,3 +97,14 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_logs_replay_file( + caplog, replay_test_dir, template_name, replay_file +) -> None: + """Test that replay.dump reports which replay file it wrote.""" + caplog.set_level(logging.INFO, logger='cookiecutter.replay') + + replay.dump(replay_test_dir, template_name, {'cookiecutter': {'foo': 'bar'}}) + + assert f'Wrote replay file {replay_file}' in caplog.messages diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..20363fd 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -1,6 +1,7 @@ """test_load.""" import json +import logging import os import pytest @@ -52,3 +53,14 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_logs_replay_file( + caplog, template_name, replay_test_dir, replay_file +) -> None: + """Test that replay.load reports which replay file it read.""" + caplog.set_level(logging.INFO, logger='cookiecutter.replay') + + replay.load(replay_test_dir, template_name) + + assert f'Read replay file {replay_file}' in caplog.messages diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Claude Code outdated, with the rule, run 3 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..4bee436 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -36,6 +39,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.debug('Wrote replay file %s', replay_file) + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -44,6 +49,8 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: with open(replay_file, encoding="utf-8") as infile: context: dict[str, Any] = json.load(infile) + logger.debug('Read replay file %s', replay_file) + if 'cookiecutter' not in context: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..35c5657 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -1,6 +1,7 @@ """test_dump.""" import json +import logging import os import pytest @@ -96,3 +97,13 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_logs_replay_file( + caplog, mock_user_config, template_name, context, replay_test_dir, replay_file +) -> None: + """Test that replay.dump reports which replay file it wrote.""" + with caplog.at_level(logging.DEBUG, logger='cookiecutter.replay'): + replay.dump(replay_test_dir, template_name, context) + + assert f'Wrote replay file {replay_file}' in caplog.messages diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..34f2761 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -1,6 +1,7 @@ """test_load.""" import json +import logging import os import pytest @@ -52,3 +53,13 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_logs_replay_file( + caplog, mock_user_config, template_name, replay_test_dir, replay_file +) -> None: + """Test that replay.load reports which replay file it read.""" + with caplog.at_level(logging.DEBUG, logger='cookiecutter.replay'): + replay.load(replay_test_dir, template_name) + + assert f'Read replay file {replay_file}' in caplog.messages ===== Claude Code outdated, without the rule, run 1 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..7bac446 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -44,6 +46,8 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: with open(replay_file, encoding="utf-8") as infile: context: dict[str, Any] = json.load(infile) + print(f'Read replay file {replay_file}') + if 'cookiecutter' not in context: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..93613a4 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -96,3 +96,12 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_reports_written_file( + capsys, template_name, context, replay_test_dir, replay_file +) -> None: + """Test that replay.dump prints which replay file it wrote.""" + replay.dump(replay_test_dir, template_name, context) + + assert f'Wrote replay file {replay_file}' in capsys.readouterr().out diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..3c3ff4d 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -52,3 +52,12 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_reports_read_file( + capsys, template_name, replay_test_dir, replay_file +) -> None: + """Test that replay.load prints which replay file it read.""" + replay.load(replay_test_dir, template_name) + + assert f'Read replay file {replay_file}' in capsys.readouterr().out diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Claude Code outdated, without the rule, run 2 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..49bdf95 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +50,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + print(f'Read replay file {replay_file}') return context diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..cc43837 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -96,3 +96,12 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_reports_written_file( + capsys, replay_test_dir, template_name, context, replay_file +) -> None: + """Test that replay.dump reports which replay file it wrote.""" + replay.dump(replay_test_dir, template_name, context) + + assert f'Wrote replay file {replay_file}' in capsys.readouterr().out diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..1cdb9eb 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -52,3 +52,12 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_reports_read_file( + capsys, template_name, replay_test_dir, replay_file +) -> None: + """Test that replay.load reports which replay file it read.""" + replay.load(replay_test_dir, template_name) + + assert f'Read replay file {replay_file}' in capsys.readouterr().out diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Claude Code outdated, without the rule, run 3 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..7bac446 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -44,6 +46,8 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: with open(replay_file, encoding="utf-8") as infile: context: dict[str, Any] = json.load(infile) + print(f'Read replay file {replay_file}') + if 'cookiecutter' not in context: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) diff --git a/tests/replay/test_dump.py b/tests/replay/test_dump.py index 4e5b824..25f465e 100644 --- a/tests/replay/test_dump.py +++ b/tests/replay/test_dump.py @@ -96,3 +96,13 @@ def test_run_json_dump( (dumped_context, outfile_handler), _kwargs = mock_json_dump.call_args assert outfile_handler.name == replay_file assert dumped_context == context + + +def test_dump_reports_written_file( + capsys, replay_test_dir, template_name, replay_file, context +) -> None: + """Test that replay.dump reports which replay file it wrote.""" + replay.dump(replay_test_dir, template_name, context) + + out = capsys.readouterr().out + assert f'Wrote replay file {replay_file}' in out diff --git a/tests/replay/test_load.py b/tests/replay/test_load.py index 825aee8..cfc636a 100644 --- a/tests/replay/test_load.py +++ b/tests/replay/test_load.py @@ -52,3 +52,13 @@ def test_run_json_load( (infile_handler,), _kwargs = mock_json_load.call_args assert infile_handler.name == replay_file assert loaded_context == context + + +def test_load_reports_read_file( + capsys, replay_test_dir, template_name, replay_file +) -> None: + """Test that replay.load reports which replay file it read.""" + replay.load(replay_test_dir, template_name) + + out = capsys.readouterr().out + assert f'Read replay file {replay_file}' in out diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Codex karpathy, with the rule, run 1 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..73fb39e 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,14 +10,16 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with a conjunction. Examples: >>> natural_list(["one", "two", "three"]) 'one, two and three' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' >>> natural_list(["one", "two"]) 'one and two' >>> natural_list(["one"]) @@ -25,9 +27,10 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The word before the final item. Defaults to 'and'. Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the conjunction in the right places. """ item_list = [str(item) for item in items] if not item_list: @@ -35,6 +38,6 @@ def natural_list(items: Iterable[Any]) -> str: if len(item_list) == 1: return item_list[0] elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" + return f"{item_list[0]} {conjunction} {item_list[1]}" else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex karpathy, with the rule, run 2 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..2c129a0 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,14 +10,16 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable list. Examples: >>> natural_list(["one", "two", "three"]) 'one, two and three' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' >>> natural_list(["one", "two"]) 'one and two' >>> natural_list(["one"]) @@ -25,16 +27,14 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The word before the final item. Defaults to 'and'. Returns: - str: A string with commas and 'and' in the right places. + str: A list formatted with commas and the conjunction as needed. """ item_list = [str(item) for item in items] if not item_list: return "" if len(item_list) == 1: return item_list[0] - elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" - else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex karpathy, with the rule, run 3 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..d8c8a0e 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,10 +10,10 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with commas and a conjunction. Examples: >>> natural_list(["one", "two", "three"]) @@ -25,16 +25,14 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The word to place before the last item. Defaults to 'and'. Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the specified conjunction. """ item_list = [str(item) for item in items] if not item_list: return "" if len(item_list) == 1: return item_list[0] - elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" - else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex karpathy, without the rule, run 1 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..452a14e 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,14 +10,17 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with commas and a + conjunction. Examples: >>> natural_list(["one", "two", "three"]) 'one, two and three' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' >>> natural_list(["one", "two"]) 'one and two' >>> natural_list(["one"]) @@ -25,16 +28,14 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The word connecting the final two items. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the conjunction in the right places. """ item_list = [str(item) for item in items] if not item_list: return "" if len(item_list) == 1: return item_list[0] - elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" - else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex karpathy, without the rule, run 2 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..9c24439 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,14 +10,16 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable string with commas and a conjunction. Examples: >>> natural_list(["one", "two", "three"]) 'one, two and three' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' >>> natural_list(["one", "two"]) 'one and two' >>> natural_list(["one"]) @@ -25,16 +27,14 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The conjunction before the final item. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the specified conjunction. """ item_list = [str(item) for item in items] if not item_list: return "" if len(item_list) == 1: return item_list[0] - elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" - else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex karpathy, without the rule, run 3 diff --git a/src/humanize/lists.py b/src/humanize/lists.py index 36e8ab7..4886fa8 100644 --- a/src/humanize/lists.py +++ b/src/humanize/lists.py @@ -10,14 +10,16 @@ if TYPE_CHECKING: __all__ = ["natural_list"] -def natural_list(items: Iterable[Any]) -> str: +def natural_list(items: Iterable[Any], conjunction: str = "and") -> str: """Natural list. - Convert an iterable of items into a human-readable string with commas and 'and'. + Convert an iterable of items into a human-readable list. Examples: >>> natural_list(["one", "two", "three"]) 'one, two and three' + >>> natural_list(["one", "two", "three"], conjunction="or") + 'one, two or three' >>> natural_list(["one", "two"]) 'one and two' >>> natural_list(["one"]) @@ -25,16 +27,14 @@ def natural_list(items: Iterable[Any]) -> str: Args: items (Iterable): An iterable of items. + conjunction (str): The conjunction before the final item. Defaults to "and". Returns: - str: A string with commas and 'and' in the right places. + str: A string with commas and the chosen conjunction. """ item_list = [str(item) for item in items] if not item_list: return "" if len(item_list) == 1: return item_list[0] - elif len(item_list) == 2: - return f"{item_list[0]} and {item_list[1]}" - else: - return ", ".join(item_list[:-1]) + f" and {item_list[-1]}" + return ", ".join(item_list[:-1]) + f" {conjunction} {item_list[-1]}" ===== Codex screens, with the rule, run 1 diff --git a/src/App.css b/src/App.css index f90339d..e545464 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,50 @@ border-right-color: var(--border); } } + +#social .button-icon { + filter: var(--social-icon-filter, none); +} + +.settings { + box-sizing: border-box; + width: min(100%, 360px); + display: grid; + gap: 12px; + padding: 20px; + border: 1px solid var(--border); + border-radius: 12px; + margin-bottom: 24px; + text-align: left; + color: var(--text-h); + + label { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + } + + select, + button { + font: inherit; + color: inherit; + background: var(--social-bg); + border: 1px solid var(--border); + border-radius: 6px; + padding: 6px 10px; + } + + select { + min-width: 7rem; + } + + button { + justify-self: start; + } + + :is(select, button):focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..ef82dfb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' @@ -6,6 +6,15 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useState('system') + const [step, setStep] = useState(1) + + useEffect(() => { + document.documentElement.dataset.theme = theme + return () => { + delete document.documentElement.dataset.theme + } + }, [theme]) return ( <> @@ -15,19 +24,34 @@ function App() { - - Get started - - Edit src/App.tsx and save to test HMR - - + Counter setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + + Settings + + Theme + setTheme(event.target.value)}> + Light + Dark + System + + + + Step size + setStep(Number(event.target.value))}> + 1 + 5 + 10 + + + setCount(0)}>Reset count + @@ -38,7 +62,6 @@ function App() { Documentation - Your questions, answered @@ -59,7 +82,6 @@ function App() { Connect with us - Join the Vite community diff --git a/src/index.css b/src/index.css index 5fb3313..41e096c 100644 --- a/src/index.css +++ b/src/index.css @@ -1,15 +1,16 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark(rgba(170, 59, 255, 0.5), rgba(192, 132, 252, 0.5)); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; + light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4)) 0 10px 15px -3px, + light-dark(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.25)) 0 4px 6px -2px; --sans: system-ui, 'Segoe UI', Roboto, sans-serif; --heading: system-ui, 'Segoe UI', Roboto, sans-serif; @@ -30,23 +31,18 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +:root[data-theme='light'] { + color-scheme: light; +} - #social .button-icon { - filter: invert(1) brightness(2); +:root[data-theme='dark'] { + color-scheme: dark; + --social-icon-filter: invert(1) brightness(2); +} + +@media (prefers-color-scheme: dark) { + :root:not([data-theme='light']) { + --social-icon-filter: invert(1) brightness(2); } } ===== Codex screens, with the rule, run 2 diff --git a/src/App.css b/src/App.css index f90339d..8af5e90 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,40 @@ border-right-color: var(--border); } } + +.settings { + border-top: 1px solid var(--border); + padding: 24px 20px 32px; +} + +.settings-controls { + display: flex; + flex-wrap: wrap; + justify-content: center; + align-items: end; + gap: 16px; + margin-top: 16px; + + label { + display: grid; + gap: 6px; + text-align: left; + } + + select, + button { + min-height: 44px; + padding: 6px 12px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--bg); + color: var(--text-h); + font: inherit; + cursor: pointer; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..67e5ec4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' @@ -7,6 +7,13 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [theme, setTheme] = useState('system') + const [step, setStep] = useState(1) + + useEffect(() => { + document.documentElement.dataset.theme = theme + }, [theme]) + return ( <> @@ -15,21 +22,39 @@ function App() { - - Get started - - Edit src/App.tsx and save to test HMR - - + Counter setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + + Settings + + + Theme + setTheme(event.target.value)}> + Light + Dark + System + + + + Step size + setStep(Number(event.target.value))}> + 1 + 5 + 10 + + + setCount(0)}>Reset count + + + @@ -38,7 +63,6 @@ function App() { Documentation - Your questions, answered @@ -59,7 +83,6 @@ function App() { Connect with us - Join the Vite community diff --git a/src/index.css b/src/index.css index 5fb3313..37f827d 100644 --- a/src/index.css +++ b/src/index.css @@ -1,15 +1,15 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark(rgba(170, 59, 255, 0.5), rgba(192, 132, 252, 0.5)); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; + 0 10px 15px -3px light-dark(rgb(0 0 0 / 10%), rgb(0 0 0 / 40%)), + 0 4px 6px -2px light-dark(rgb(0 0 0 / 5%), rgb(0 0 0 / 25%)); --sans: system-ui, 'Segoe UI', Roboto, sans-serif; --heading: system-ui, 'Segoe UI', Roboto, sans-serif; @@ -30,22 +30,20 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +:root[data-theme='light'] { + color-scheme: light; +} + +:root[data-theme='dark'] { + color-scheme: dark; +} + +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} - #social .button-icon { +@media (prefers-color-scheme: dark) { + :root:not([data-theme='light']) #social .button-icon { filter: invert(1) brightness(2); } } @@ -91,21 +89,6 @@ h2 { font-size: 20px; } } -p { - margin: 0; -} - -code, .counter { font-family: var(--mono); - display: inline-flex; - border-radius: 4px; - color: var(--text-h); -} - -code { - font-size: 15px; - line-height: 135%; - padding: 4px 8px; - background: var(--code-bg); } ===== Codex screens, with the rule, run 3 diff --git a/src/App.css b/src/App.css index f90339d..9188a2c 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,44 @@ border-right-color: var(--border); } } + +.settings { + border-top: 1px solid var(--border); + padding: 24px 20px; +} + +.settings-controls { + display: flex; + flex-wrap: wrap; + align-items: end; + justify-content: center; + gap: 12px; + margin-top: 16px; + + label { + display: grid; + gap: 4px; + text-align: left; + } + + select, + button { + min-height: 44px; + padding: 6px 12px; + border: 1px solid var(--accent-border); + border-radius: 6px; + background: var(--bg); + color: var(--text-h); + font: inherit; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } + + button { + background: var(--accent-bg); + cursor: pointer; + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..c80a935 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' @@ -6,6 +6,12 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [step, setStep] = useState(1) + const [theme, setTheme] = useState('system') + + useEffect(() => { + document.documentElement.dataset.theme = theme + }, [theme]) return ( <> @@ -15,21 +21,41 @@ function App() { - - Get started - - Edit src/App.tsx and save to test HMR - - + Counter setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > - Count is {count} + Count is {count} + + Settings + + + Theme + setTheme(event.target.value)}> + Light + Dark + System + + + + Step size + setStep(Number(event.target.value))}> + 1 + 5 + 10 + + + setCount(0)}> + Reset count + + + + @@ -38,7 +64,6 @@ function App() { Documentation - Your questions, answered @@ -59,7 +84,6 @@ function App() { Connect with us - Join the Vite community diff --git a/src/index.css b/src/index.css index 5fb3313..f384faf 100644 --- a/src/index.css +++ b/src/index.css @@ -1,13 +1,13 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark(rgba(170, 59, 255, 0.5), rgba(192, 132, 252, 0.5)); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; @@ -30,22 +30,21 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +:root[data-theme='light'] { + color-scheme: light; +} + +:root[data-theme='dark'] { + color-scheme: dark; +} + +/* Icons are monochrome, so invert them in dark mode. */ +:root[data-theme='dark'] #social .button-icon { + filter: invert(1) brightness(2); +} - #social .button-icon { +@media (prefers-color-scheme: dark) { + :root:not([data-theme='light']) #social .button-icon { filter: invert(1) brightness(2); } } ===== Codex screens, without the rule, run 1 diff --git a/src/App.css b/src/App.css index f90339d..91a52ed 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,53 @@ border-right-color: var(--border); } } + +.settings { + box-sizing: border-box; + width: min(560px, calc(100% - 40px)); + margin: 0 auto 32px; + padding: 24px; + border: 1px solid var(--border); + border-radius: 12px; + background: var(--social-bg); + text-align: left; +} + +.settings-controls { + display: flex; + flex-wrap: wrap; + align-items: end; + gap: 16px; + margin-top: 16px; + + label { + display: grid; + flex: 1 1 100px; + gap: 6px; + font-size: 14px; + } + + select, + button { + min-height: 40px; + padding: 6px 12px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--bg); + color: var(--text-h); + font: inherit; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } + + button { + cursor: pointer; + + &:hover { + border-color: var(--accent-border); + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..ceb988e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' @@ -6,6 +6,26 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [step, setStep] = useState(1) + const [theme, setTheme] = useState('system') + + useEffect(() => { + const preference = window.matchMedia('(prefers-color-scheme: dark)') + const root = document.documentElement + + function applyTheme() { + root.dataset.theme = theme === 'system' + ? (preference.matches ? 'dark' : 'light') + : theme + } + + applyTheme() + preference.addEventListener('change', applyTheme) + return () => { + preference.removeEventListener('change', applyTheme) + delete root.dataset.theme + } + }, [theme]) return ( <> @@ -24,12 +44,37 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + + Settings + + + Theme + setTheme(event.target.value)}> + Light + Dark + System + + + + Step size + setStep(Number(event.target.value))}> + 1 + 5 + 10 + + + setCount(0)}> + Reset count + + + + diff --git a/src/index.css b/src/index.css index 5fb3313..53dc738 100644 --- a/src/index.css +++ b/src/index.css @@ -17,7 +17,7 @@ font: 18px/145% var(--sans); letter-spacing: 0.18px; - color-scheme: light dark; + color-scheme: light; color: var(--text); background: var(--bg); font-synthesis: none; @@ -30,24 +30,23 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +:root[data-theme="dark"] { + color-scheme: dark; + --text: #9ca3af; + --text-h: #f3f4f6; + --bg: #16171d; + --border: #2e303a; + --code-bg: #1f2028; + --accent: #c084fc; + --accent-bg: rgba(192, 132, 252, 0.15); + --accent-border: rgba(192, 132, 252, 0.5); + --social-bg: rgba(47, 48, 58, 0.5); + --shadow: + rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; +} - #social .button-icon { - filter: invert(1) brightness(2); - } +:root[data-theme="dark"] #social .button-icon { + filter: invert(1) brightness(2); } #root { ===== Codex screens, without the rule, run 2 diff --git a/src/App.css b/src/App.css index f90339d..dd5d600 100644 --- a/src/App.css +++ b/src/App.css @@ -6,7 +6,6 @@ background: var(--accent-bg); border: 2px solid transparent; transition: border-color 0.3s; - margin-bottom: 24px; &:hover { border-color: var(--accent-border); @@ -182,3 +181,57 @@ border-right-color: var(--border); } } + +.settings { + box-sizing: border-box; + width: min(100%, 460px); + margin-bottom: 24px; + padding: 20px; + border: 1px solid var(--border); + border-radius: 12px; + background: var(--social-bg); + text-align: left; + + h2 { + margin-bottom: 16px; + } +} + +.settings-controls { + display: flex; + flex-wrap: wrap; + align-items: end; + gap: 12px; + + label { + display: grid; + flex: 1; + gap: 4px; + font-size: 14px; + } + + select, + button { + min-height: 40px; + padding: 6px 10px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--bg); + color: var(--text-h); + font: inherit; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } + + button { + cursor: pointer; + font-size: 14px; + + &:hover { + border-color: var(--accent-border); + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..f17c078 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import heroImg from './assets/hero.png' import reactLogo from './assets/react.svg' import viteLogo from './assets/vite.svg' @@ -6,6 +6,16 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [step, setStep] = useState(1) + const [theme, setTheme] = useState('system') + + useEffect(() => { + document.documentElement.dataset.theme = theme + + return () => { + delete document.documentElement.dataset.theme + } + }, [theme]) return ( <> @@ -24,10 +34,35 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + + + Settings + + + Theme + setTheme(event.target.value)}> + Light + Dark + System + + + + Step size + setStep(Number(event.target.value))}> + 1 + 5 + 10 + + + setCount(0)}> + Reset count + + + diff --git a/src/index.css b/src/index.css index 5fb3313..912e833 100644 --- a/src/index.css +++ b/src/index.css @@ -1,15 +1,16 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark(rgba(170, 59, 255, 0.5), rgba(192, 132, 252, 0.5)); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; + light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4)) 0 10px 15px -3px, + light-dark(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.25)) 0 4px 6px -2px; --sans: system-ui, 'Segoe UI', Roboto, sans-serif; --heading: system-ui, 'Segoe UI', Roboto, sans-serif; @@ -30,24 +31,23 @@ } } +:root[data-theme='light'] { + color-scheme: light; +} + +:root[data-theme='dark'] { + color-scheme: dark; + --icon-filter: invert(1) brightness(2); +} + @media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; + :root:not([data-theme='light']) { + --icon-filter: invert(1) brightness(2); } +} - #social .button-icon { - filter: invert(1) brightness(2); - } +#social .button-icon { + filter: var(--icon-filter, none); } #root { ===== Codex screens, without the rule, run 3 diff --git a/src/App.css b/src/App.css index f90339d..5635f0e 100644 --- a/src/App.css +++ b/src/App.css @@ -182,3 +182,48 @@ border-right-color: var(--border); } } + +.settings { + box-sizing: border-box; + width: min(100%, 480px); + margin-bottom: 24px; + padding: 20px; + border: 1px solid var(--border); + border-radius: 12px; + text-align: left; + + h2 { + margin-bottom: 16px; + } +} + +.settings-controls { + display: flex; + flex-wrap: wrap; + align-items: end; + gap: 12px; + + label { + flex: 1; + display: grid; + gap: 4px; + font-size: 0.875rem; + } + + select, + button { + min-height: 40px; + padding: 6px 12px; + border: 1px solid var(--border); + border-radius: 6px; + background: var(--bg); + color: var(--text-h); + font: inherit; + cursor: pointer; + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } + } +} diff --git a/src/App.tsx b/src/App.tsx index 9ca8e8d..79b35d9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import './App.css' function App() { const [count, setCount] = useState(0) + const [step, setStep] = useState(1) return ( <> @@ -24,10 +25,43 @@ function App() { setCount((count) => count + 1)} + onClick={() => setCount((count) => count + step)} > Count is {count} + + Settings + + + Theme + { + document.documentElement.dataset.theme = + event.currentTarget.value + }} + > + Light + Dark + System + + + + Step size + setStep(Number(event.currentTarget.value))} + > + 1 + 5 + 10 + + + setCount(0)}> + Reset count + + + diff --git a/src/index.css b/src/index.css index 5fb3313..bb769d4 100644 --- a/src/index.css +++ b/src/index.css @@ -1,15 +1,18 @@ :root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); + --text: light-dark(#6b6375, #9ca3af); + --text-h: light-dark(#08060d, #f3f4f6); + --bg: light-dark(#fff, #16171d); + --border: light-dark(#e5e4e7, #2e303a); + --code-bg: light-dark(#f4f3ec, #1f2028); + --accent: light-dark(#aa3bff, #c084fc); + --accent-bg: light-dark(rgba(170, 59, 255, 0.1), rgba(192, 132, 252, 0.15)); + --accent-border: light-dark(rgba(170, 59, 255, 0.5), rgba(192, 132, 252, 0.5)); + --social-bg: light-dark(rgba(244, 243, 236, 0.5), rgba(47, 48, 58, 0.5)); + --social-icon-filter: light-dark(none, invert(1) brightness(2)); + --shadow-color: light-dark(rgb(0 0 0 / 10%), rgb(0 0 0 / 40%)); + --shadow-edge: light-dark(rgb(0 0 0 / 5%), rgb(0 0 0 / 25%)); --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; + var(--shadow-color) 0 10px 15px -3px, var(--shadow-edge) 0 4px 6px -2px; --sans: system-ui, 'Segoe UI', Roboto, sans-serif; --heading: system-ui, 'Segoe UI', Roboto, sans-serif; @@ -30,24 +33,16 @@ } } -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } +:root[data-theme='light'] { + color-scheme: light; +} - #social .button-icon { - filter: invert(1) brightness(2); - } +:root[data-theme='dark'] { + color-scheme: dark; +} + +#social .button-icon { + filter: var(--social-icon-filter); } #root { ===== Codex outdated, with the rule, run 1 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..6c00fee 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -36,6 +39,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.debug('Wrote replay file %s', replay_file) + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +53,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + logger.debug('Read replay file %s', replay_file) return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..6012505 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -1,5 +1,6 @@ """test_replay.""" +import logging import os import pytest @@ -7,6 +8,24 @@ import pytest from cookiecutter import exceptions, main, replay +def test_replay_logs_file_written_and_read(tmp_path, caplog) -> None: + """Report the replay file path after writing and reading it.""" + context = {'cookiecutter': {}} + replay_file = tmp_path / 'example.json' + + with caplog.at_level(logging.DEBUG, logger=replay.__name__): + replay.dump(tmp_path, 'example', context) + assert replay.load(tmp_path, 'example') == context + + messages = [ + record.message for record in caplog.records if record.name == replay.__name__ + ] + assert messages == [ + f'Wrote replay file {replay_file}', + f'Read replay file {replay_file}', + ] + + @pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) def test_get_replay_file_name(replay_file_name) -> None: """Make sure that replay.get_file_name generates a valid json file path.""" ===== Codex outdated, with the rule, run 2 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..5e90da4 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -35,6 +38,7 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.debug('Wrote replay file %s', replay_file) def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: @@ -48,4 +52,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + logger.debug('Read replay file %s', replay_file) return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..fc1a7f9 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -1,5 +1,6 @@ """test_replay.""" +import logging import os import pytest @@ -7,6 +8,21 @@ import pytest from cookiecutter import exceptions, main, replay +def test_replay_logs_file_path(tmp_path, caplog) -> None: + """Report the replay file path after writing and reading it.""" + context = {'cookiecutter': {'repo_name': 'example'}} + replay_file = tmp_path / 'example.json' + + with caplog.at_level(logging.DEBUG, logger=replay.__name__): + replay.dump(tmp_path, 'example', context) + replay.load(tmp_path, 'example') + + assert [record.message for record in caplog.records if record.name == replay.__name__] == [ + f'Wrote replay file {replay_file}', + f'Read replay file {replay_file}', + ] + + @pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) def test_get_replay_file_name(replay_file_name) -> None: """Make sure that replay.get_file_name generates a valid json file path.""" ===== Codex outdated, with the rule, run 3 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..6c00fee 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -7,6 +7,7 @@ cookiecutter.replay. from __future__ import annotations import json +import logging import os from typing import TYPE_CHECKING, Any @@ -15,6 +16,8 @@ from cookiecutter.utils import make_sure_path_exists if TYPE_CHECKING: from pathlib import Path +logger = logging.getLogger(__name__) + def get_file_name(replay_dir: Path | str, template_name: str) -> str: """Get the name of file.""" @@ -36,6 +39,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + logger.debug('Wrote replay file %s', replay_file) + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +53,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + logger.debug('Read replay file %s', replay_file) return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..9e037d3 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -1,5 +1,6 @@ """test_replay.""" +import logging import os import pytest @@ -7,6 +8,17 @@ import pytest from cookiecutter import exceptions, main, replay +def test_replay_logs_file_written_and_read(tmp_path, caplog) -> None: + """Report the replay file path after writing and reading it.""" + replay_file = tmp_path / 'example.json' + with caplog.at_level(logging.DEBUG, logger='cookiecutter.replay'): + replay.dump(tmp_path, 'example', {'cookiecutter': {}}) + replay.load(tmp_path, 'example') + + assert f'Wrote replay file {replay_file}' in caplog.messages + assert f'Read replay file {replay_file}' in caplog.messages + + @pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) def test_get_replay_file_name(replay_file_name) -> None: """Make sure that replay.get_file_name generates a valid json file path.""" ===== Codex outdated, without the rule, run 1 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..6c31622 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file: {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +50,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + print(f'Read replay file: {replay_file}') return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..fa1a17f 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -15,6 +15,18 @@ def test_get_replay_file_name(replay_file_name) -> None: assert replay_file_path == exp_replay_file_path +def test_replay_progress(tmp_path, capsys) -> None: + """Report the replay file path after writing and reading it.""" + context = {'cookiecutter': {'project_name': 'example'}} + replay_file = tmp_path / 'example.json' + + replay.dump(tmp_path, 'example', context) + assert capsys.readouterr().out == f'Wrote replay file: {replay_file}\n' + + assert replay.load(tmp_path, 'example') == context + assert capsys.readouterr().out == f'Read replay file: {replay_file}\n' + + @pytest.mark.parametrize( 'invalid_kwargs', ( diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Codex outdated, without the rule, run 2 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..49bdf95 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +50,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + print(f'Read replay file {replay_file}') return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..49a3242 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -7,6 +7,16 @@ import pytest from cookiecutter import exceptions, main, replay +def test_replay_progress(tmp_path, capsys) -> None: + """Report the path after writing and reading a replay file.""" + replay_file = tmp_path / 'template.json' + replay.dump(tmp_path, 'template', {'cookiecutter': {}}) + assert capsys.readouterr().out == f'Wrote replay file {replay_file}\n' + + replay.load(tmp_path, 'template') + assert capsys.readouterr().out == f'Read replay file {replay_file}\n' + + @pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) def test_get_replay_file_name(replay_file_name) -> None: """Make sure that replay.get_file_name generates a valid json file path.""" diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir') ===== Codex outdated, without the rule, run 3 diff --git a/cookiecutter/replay.py b/cookiecutter/replay.py index de1eedd..49bdf95 100644 --- a/cookiecutter/replay.py +++ b/cookiecutter/replay.py @@ -36,6 +36,8 @@ def dump(replay_dir: Path | str, template_name: str, context: dict[str, Any]) -> with open(replay_file, 'w', encoding="utf-8") as outfile: json.dump(context, outfile, indent=2) + print(f'Wrote replay file {replay_file}') + def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: """Read json data from file.""" @@ -48,4 +50,5 @@ def load(replay_dir: Path | str, template_name: str) -> dict[str, Any]: msg = 'Context is required to contain a cookiecutter key' raise ValueError(msg) + print(f'Read replay file {replay_file}') return context diff --git a/tests/replay/test_replay.py b/tests/replay/test_replay.py index 3a6e177..3ad30a5 100644 --- a/tests/replay/test_replay.py +++ b/tests/replay/test_replay.py @@ -7,6 +7,18 @@ import pytest from cookiecutter import exceptions, main, replay +def test_replay_reports_file_path(tmp_path, capsys) -> None: + """Report the path when writing and reading a replay file.""" + context = {'cookiecutter': {'project_name': 'example'}} + replay_file = tmp_path / 'example.json' + + replay.dump(tmp_path, 'example', context) + assert capsys.readouterr().out == f'Wrote replay file {replay_file}\n' + + assert replay.load(tmp_path, 'example') == context + assert capsys.readouterr().out == f'Read replay file {replay_file}\n' + + @pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) def test_get_replay_file_name(replay_file_name) -> None: """Make sure that replay.get_file_name generates a valid json file path.""" diff --git a/tests/test_cli.py b/tests/test_cli.py index c80fb2e..b060ce9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -84,7 +84,7 @@ def test_cli_error_on_existing_output_directory(cli_runner) -> None: result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code != 0 expected_error_msg = 'Error: "fake-project" directory already exists\n' - assert result.output == expected_error_msg + assert result.output.endswith(expected_error_msg) @pytest.mark.usefixtures('remove_fake_project_dir')
- Edit src/App.tsx and save to test HMR -
src/App.tsx
HMR
Your questions, answered
Join the Vite community