Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike out select style inputs for keyword-based properties #35

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Spike out select style inputs for keyword-based properties
  • Loading branch information
johno committed Apr 22, 2022
commit b5027f43d7a1d127e23c4d6d2d3113ec08ad0bac
2 changes: 1 addition & 1 deletion apps/docs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Theme } from '@emotion/react'
const initialStyles: any = {
fontSize: { value: 16, unit: 'px' },
lineHeight: { value: 1.4, unit: 'number' },
textAlign: 'inherit',
color: 'tomato',
backgroundColor: 'black',
textAlign: 'inherit',
}
const DEFAULT_THEME: Theme = {
fontSizes: [
Expand Down
2 changes: 2 additions & 0 deletions packages/gui/src/components/Editor/map.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { FontSizeInput, LineHeightInput } from '../editors'
import { BackgroundColorInput, ColorInput } from '../editors/ColorInputs'
import { TextAlignInput } from '../editors/KeywordInputs'

export const controlMap: Record<string, any> = {
fontSize: FontSizeInput,
lineHeight: LineHeightInput,
color: ColorInput,
backgroundColor: BackgroundColorInput,
textAlign: TextAlignInput,
}
16 changes: 13 additions & 3 deletions packages/gui/src/components/editors/ColorInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { useId } from 'react'
import { ColorPopover, Label } from '../primitives'
import { ColorEditorProps } from './types'

const DEFAULT_BACKGROUND_COLOR = '#fff'
export const BackgroundColorInput = ({ value, onChange }: ColorEditorProps) => {
const id = useId()
const fullId = `${id}-backgroundColor`
return (
<>
<Label>Background color</Label>
<Label htmlFor={fullId}>Background color</Label>
<ColorPopover
id={fullId}
value={value || DEFAULT_BACKGROUND_COLOR}
onChange={onChange}
/>
Expand All @@ -16,10 +20,16 @@ export const BackgroundColorInput = ({ value, onChange }: ColorEditorProps) => {

const DEFAULT_COLOR = '#000'
export const ColorInput = ({ value, onChange }: ColorEditorProps) => {
const id = useId()
const fullId = `${id}-color`
return (
<>
<Label>Color</Label>
<ColorPopover value={value || DEFAULT_COLOR} onChange={onChange} />
<Label htmlFor={fullId}>Color</Label>
<ColorPopover
id={fullId}
value={value || DEFAULT_COLOR}
onChange={onChange}
/>
</>
)
}
47 changes: 47 additions & 0 deletions packages/gui/src/components/editors/KeywordInputs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ChangeEvent, useId } from 'react'
import { getPropertyData } from '../../data/properties'
import { Label } from '../primitives'
import { KeywordEditorProps } from './types'

const DEFAULT_TEXT_ALIGN = 'inherit'
const textAlignKeywords = getPropertyData('textAlign')!
export const TextAlignInput = ({ value, onChange }: KeywordEditorProps) => {
const id = useId()
const fullId = `${id}-textAlign`
return (
<>
<Label htmlFor={fullId}>Text align</Label>
<Select
id={fullId}
value={value || DEFAULT_TEXT_ALIGN}
onChange={onChange}
values={textAlignKeywords.keywords}
/>
</>
)
}

type SelectProps = {
id: string
onChange: (newValue: string) => void
values: string[]
value: string
}
export const Select = ({ value, onChange, id, values }: SelectProps): any => {
return (
<select
id={id}
value={value}
onChange={(e: ChangeEvent<HTMLSelectElement>) => onChange(e.target.value)}
sx={{ width: '100%', minHeight: '1.6em' }}
>
{values.map((v) => {
return (
<option key={v} value={v}>
{v}
</option>
)
})}
</select>
)
}
5 changes: 5 additions & 0 deletions packages/gui/src/components/editors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export type LengthEditorProps = {
onChange: (newValue: Length | ResponsiveLength) => void
}

export type KeywordEditorProps = {
value?: string
onChange: (newValue: string) => void
}

export type ColorEditorProps = {
value?: Color
onChange: (newValue: Color) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Props extends PickerProps {
showText?: boolean
/** The element to render on the swatch preview */
swatch?: JSX.Element
id?: string
}

/**
Expand Down