Skip to content

Commit

Permalink
Add better-typed entries fn for palette form
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Jun 13, 2024
1 parent 8cb223e commit 10213da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 4 additions & 7 deletions fronts-client/src/components/form/PaletteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { State } from 'types/State';
import InputLabel from 'components/inputs/InputLabel';
import { InputColor } from 'components/inputs/InputColor';
import { Palette } from 'types/Collection';
import { entries } from 'util/object';

export const createPaletteForm =
<T extends string>(formName: string, fieldName: T) =>
Expand Down Expand Up @@ -46,17 +47,13 @@ export const createPaletteForm =
return (
<>
<PaletteList>
{Object.entries(chefPalettes).map(([paletteId, palette]) => (
{entries(chefPalettes).map(([paletteId, palette]) => (
<PaletteItem
palette={palette}
key={paletteId}
id={paletteId as ChefPaletteId}
id={paletteId}
onClick={(name, foregroundHex, backgroundHex) => {
setPaletteOption(
name as ChefPaletteId,
foregroundHex,
backgroundHex
);
setPaletteOption(name, foregroundHex, backgroundHex);
onCancel();
}}
isSelected={
Expand Down
11 changes: 11 additions & 0 deletions fronts-client/src/util/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Entries<T> = {
[K in keyof T]: [K, T[K]];
}[keyof T][];

export const entries = <
Key extends string,
Value,
Obj extends Record<Key, Value>
>(
obj: Obj
): Entries<Obj> => Object.entries(obj) as Entries<Obj>;

0 comments on commit 10213da

Please sign in to comment.