Skip to content

Commit

Permalink
Forward props to inputs
Browse files Browse the repository at this point in the history
Closes #112
  • Loading branch information
johno committed May 3, 2022
1 parent 2410bdf commit 9d9c6c6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-readers-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Allow for control props to be passed to the input
18 changes: 18 additions & 0 deletions apps/docs/pages/components/editor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ export function Demo() {
)
}
```

### Customizing Inputs

When using the composition-based approach, you can customize the `label`, `steps`, `range`.

```js
<Inputs.FontSize
label="Size"
steps={{
px: 1,
em: 0.2,
}}
range={{
px: [1, 256],
em: [0.1, 16],
}}
/>
```
16 changes: 13 additions & 3 deletions packages/gui/src/components/Editor/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import { Label } from '../primitives'
import { kebabCase } from 'lodash-es'
import { useThemeProperty } from '../providers/ThemeContext'
import { PositionInput } from '../inputs/PositionInput'
import { UnitSteps } from '../../lib'
import { UnitRanges } from '../../data/ranges'

type ControlProps = {
type ControlProps = InputProps & {
field: KeyArg
}
const Control = ({ field }: ControlProps) => {
const Control = ({ field, ...props }: ControlProps) => {
const { getField, setField } = useEditor()
const fieldset = useFieldset()
const property = field.toString()
Expand Down Expand Up @@ -58,13 +60,21 @@ const Control = ({ field }: ControlProps) => {
themeValues={themeValues}
{...properties[property]}
keywords={keywords}
{...props}
/>
)
}

type InputProps = {
label?: string
steps?: UnitSteps
range?: UnitRanges
}
export const Inputs: Record<string, any> = {}
Object.keys(properties).forEach((field: string) => {
Inputs[pascal(field)] = () => <Control field={field} />
Inputs[pascal(field)] = (props: InputProps) => (
<Control {...props} field={field} />
)
})

type ControlsProps = {
Expand Down

0 comments on commit 9d9c6c6

Please sign in to comment.