Skip to content

Commit

Permalink
Merge pull request #95 from components-ai/positional-space
Browse files Browse the repository at this point in the history
Positional space
  • Loading branch information
johno authored May 2, 2022
2 parents 652a157 + 7cf0ae2 commit d91be73
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-bees-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Remove x/y shorthands for spacing
1 change: 1 addition & 0 deletions apps/docs/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const Sidebar = () => {
<NavItem href="/examples/filters">Filters</NavItem>
<NavItem href="/examples/transforms">Transforms</NavItem>
<NavItem href="/examples/border-images">Border Images</NavItem>
<NavItem href="/examples/space">Space</NavItem>
<NavSectionTitle>Community</NavSectionTitle>
<NavItem href="https://github.com/components-ai/css.gui">GitHub</NavItem>
<NavItem href="https://twitter.com/components_ai">Twitter</NavItem>
Expand Down
25 changes: 25 additions & 0 deletions apps/docs/components/examples/Space.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useState } from 'react'
import { codegen, Editor, styled } from '@compai/css-gui'

export const SpaceExample = () => {
const [styles, setStyles] = useState({
margin: { value: 16, unit: 'px' },
padding: { value: 16, unit: 'px' },
})

return (
<div>
{/** @ts-ignore */}
<Editor styles={styles} onChange={setStyles} />
<div sx={{ border: 'thin solid', borderColor: 'border', mt: [3, 4, 5] }}>
<styled.p styles={{ ...styles, border: 'thin solid' }}>
Fun with space!
</styled.p>
</div>
{/** @ts-ignore */}
<pre>{codegen.css(styles)}</pre>
<hr />
<pre>{JSON.stringify(styles, null, 2)}</pre>
</div>
)
}
84 changes: 84 additions & 0 deletions apps/docs/pages/examples/space.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { SpaceExample } from '../../components/examples/Space'

## Space

Space refers to `margin` and `padding` controls. In order to keep things
as simple as possible early on, we recommend that you use the longhand
version.

```js
import { useState } from 'react'
import { Editor, Inputs, styled, codegen } from '@compai/css-gui'

export const SpaceExample = () => {
const [styles, setStyles] = useState({
marginTop: { value: 16, unit: 'px' },
marginRight: { value: 16, unit: 'px' },
marginLeft: { value: 16, unit: 'px' },
marginBottom: { value: 16, unit: 'px' },
paddingTop: { value: 16, unit: 'px' },
paddingRight: { value: 16, unit: 'px' },
paddingLeft: { value: 16, unit: 'px' },
paddingBottom: { value: 16, unit: 'px' },
})

return (
<div>
<Editor styles={styles} onChange={setStyles}>
<Inputs.MarginTop />
<Inputs.MarginRight />
<Inputs.MarginBottom />
<Inputs.MarginLeft />
<Inputs.PaddingTop />
<Inputs.PaddingRight />
<Inputs.PaddingBottom />
<Inputs.PaddingLeft />
</Editor>
<div sx={{ border: 'thin solid', borderColor: 'border', mt: [3, 4, 5] }}>
<styled.p styles={{ ...styles, border: 'thin solid' }}>
Fun with space!
</styled.p>
</div>
<pre>{codegen.css(styles)}</pre>
<hr />
<pre>{JSON.stringify(styles, null, 2)}</pre>
</div>
)
}
```

<SpaceExample />

## Padding/Margin Shorthand

If desirable, you can also use the spacing shorthand to target all directions
at once.

```js
import { useState } from 'react'
import { Editor, Inputs, styled, codegen } from '@compai/css-gui'

export const SpaceExample = () => {
const [styles, setStyles] = useState({
margin: { value: 16, unit: 'px' },
padding: { value: 16, unit: 'px' },
})

return (
<div>
<Editor styles={styles} onChange={setStyles}>
<Inputs.Margin />
<Inputs.Padding />
</Editor>
<div sx={{ border: 'thin solid', borderColor: 'border', mt: [3, 4, 5] }}>
<styled.p styles={{ ...styles, border: 'thin solid' }}>
Fun with space!
</styled.p>
</div>
<pre>{codegen.css(styles)}</pre>
<hr />
<pre>{JSON.stringify(styles, null, 2)}</pre>
</div>
)
}
```
16 changes: 0 additions & 16 deletions packages/gui/src/data/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,14 +884,6 @@ export const properties: Record<string, PropertyData> = {
type: 'length',
percentage: true,
},
marginX: {
type: 'length',
percentage: true,
},
marginY: {
type: 'length',
percentage: true,
},
marginTop: {
type: 'length',
percentage: true,
Expand Down Expand Up @@ -1182,14 +1174,6 @@ export const properties: Record<string, PropertyData> = {
type: 'length',
percentage: true,
},
paddingX: {
type: 'length',
percentage: true,
},
paddingY: {
type: 'length',
percentage: true,
},
paddingTop: {
type: 'length',
percentage: true,
Expand Down

1 comment on commit d91be73

@vercel
Copy link

@vercel vercel bot commented on d91be73 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

css-gui – ./

css-gui-git-main-components-ai.vercel.app
css-gui.vercel.app
css-gui-components-ai.vercel.app

Please sign in to comment.