Skip to content

Commit

Permalink
feat: add css prop events
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOliveiraM committed Oct 22, 2022
1 parent 3c4a840 commit 696bf43
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react",
"typescript"
],
"version": "2.0.5",
"version": "2.1.0",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
Expand Down
43 changes: 43 additions & 0 deletions src/components/atoms/X/X.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Meta } from '@storybook/addon-docs'

import { Canvas } from 'core/storybookWrappers'

import { X } from './X'

<Meta title='Components/X' />

# X

The most powerful component from the design system. This is the FUTURE!

X component can exist as any HTML tag.

Remember, it uses all the theme settings as well as other components.

## Usage

Try using:

```tsx
<X.div>something here</X.div>
```

You can pass all the style props, see one example:

```tsx
<X.div bg='blue'>something here</X.div>
```

And you can pass css events and much more:

```tsx
<X.div bg={{ _: 'blue', hover: 'red' }}>something here</X.div>
```

See the docs for this feature [here](https://xstyled.dev/docs/hover-focus-other-states/).

This example running:

<Canvas>
<X.div bg={{ _: 'blue', hover: 'red' }}>something here</X.div>
</Canvas>
5 changes: 5 additions & 0 deletions src/components/atoms/X/X.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { x } from '@xstyled/styled-components'

const X = x

export { X }
1 change: 1 addition & 0 deletions src/components/atoms/X/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './X'
1 change: 1 addition & 0 deletions src/components/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './Divider'
export * from './Label'
export * from './Span'
export * from './A'
export * from './X'
2 changes: 1 addition & 1 deletion src/theme/css/preflight.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/addon-docs'

<Meta title='CSS/Preflight' />
<Meta title='Docs/CSS/Preflight' />

# Preflight

Expand Down
8 changes: 4 additions & 4 deletions src/theme/internal/defaultTheme.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/addon-docs'

<Meta title='Settings/Theming' />
<Meta title='Docs/Settings/Theming' />

# Defaults

Expand All @@ -10,7 +10,7 @@ account the community's best practices, so it is highly recommended to
only overwrite what is really necessary.

A React provider called `ThemeProvider` is used to set all theme values in your project.
See `Exports/Providers` in this documentation for more information about this component.
See `Docs/Exports/Providers` in this documentation for more information about this component.

**Important:** You don't need to set the whole theme from
scratch if you are creating custom theme.
Expand Down Expand Up @@ -41,7 +41,7 @@ export default RootApp
For more information about how to use and define the custom themes,
see the [themes](https://xstyled.dev/docs/theme/) section of xstyled
documentation. Take a look at how to change the specific default colors
of design system components in the `Settings/Default Colors` section.
of design system components in the `Docs/Settings/Default Colors` section.

## Defaults Definition

Expand Down Expand Up @@ -208,4 +208,4 @@ export const defaultTheme = {
}
```

The colors is defined with another method. See `Settings/Default Colors`.
The colors is defined with another method. See `Docs/Settings/Default Colors`.
2 changes: 2 additions & 0 deletions src/theme/internal/defaultTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import radii from './themeAssets/radii'
import screens from './themeAssets/screens'
import shadows from './themeAssets/shadows'
import space from './themeAssets/space'
import states from './themeAssets/states'
import transitionProperties from './themeAssets/transitionProperties'

export const defaultTheme = {
Expand All @@ -23,6 +24,7 @@ export const defaultTheme = {
screens,
shadows,
space,
states,
transitionProperties,
colors: defaultColors,
}
20 changes: 20 additions & 0 deletions src/theme/internal/themeAssets/states.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const states = {
_: null,
motionSafe: '@media (prefers-reduced-motion: no-preference)',
motionReduce: '@media (prefers-reduced-motion: reduce)',
first: '&:first-child',
last: '&:last-child',
odd: '&:odd',
even: '&:even',
visited: '&:visited',
checked: '&:checked',
focusWithin: '&:focus-within',
hover: '&:hover',
focus: '&:focus',
focusVisible: '&:focus-visible',
active: '&:active',
disabled: '&:disabled, &[aria-disabled=true]',
placeholder: '&::placeholder',
}

export default states
6 changes: 3 additions & 3 deletions src/theme/providers.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/addon-docs'

<Meta title='Exports/Providers' />
<Meta title='Docs/Exports/Providers' />

# Providers

Expand Down Expand Up @@ -29,9 +29,9 @@ export default RootApp
```

**Important:** You don't need to set the whole theme from scratch.
Look `Settings/Theming` in this documentation for more information.
Look `Docs/Settings/Theming` in this documentation for more information.

For more information about how to use and define the custom themes,
see the [themes](https://xstyled.dev/docs/theme/) section of xstyled
documentation. Take a look at how to change the specific default colors
of design system components in the `Settings/Default Colors` section.
of design system components in the `Docs/Settings/Default Colors` section.
100 changes: 100 additions & 0 deletions src/theme/styling.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Meta } from '@storybook/addon-docs'

import { Canvas } from 'core/storybookWrappers'

import { Box } from 'components/atoms/Box'

<Meta title='Docs/Styling' />

# Advanced props

You can pass css events to all design system components like:

```tsx
<Box p='2rem' bg={{ _: 'blue', hover: 'red' }} color={{ _: 'white', hover: 'black' }}>
something here
</Box>
```

This example running (try hover):

<Canvas>
<Box p='2rem' bg={{ _: 'blue', hover: 'red' }} color={{ _: 'white', hover: 'black' }}>
something here
</Box>
</Canvas>

## Using reponsive states

States and breakpoints can be seemlessly mixed, every screens defined in theme are a `@media (min-width: ...)` state.

```jsx preview color=fuchsia
<>
<template preview>
<x.div textAlign='center'>
<x.button
type='button'
py={2}
px={4}
bg={{
_: { _: 'indigo-500', hover: 'indigo-700' },
md: { _: 'fuchsia-500', hover: 'fuchsia-700' },
}}
color='white'
fontWeight='semibold'
borderRadius='lg'
boxShadow='md'
outline={{ focus: 'none ' }}
tabindex='-1'
>
Cameleon button
</x.button>
</x.div>
</template>
<x.button
bg={{
_: { _: 'indigo-500', hover: 'indigo-700' },
md: { _: 'fuchsia-500', hover: 'fuchsia-700' },
}}
>
Cameleon button
</x.button>
</>
```

## Available states

Default theme includes a set of useful states.

| State Prefix | CSS Scope |
| -------------- | ------------------------------------------------ |
| `motionSafe` | `@media (prefers-reduced-motion: no-preference)` |
| `motionReduce` | `@media (prefers-reduced-motion: reduce)` |
| `first` | `&:first-child` |
| `last` | `&:last-child` |
| `odd` | `&:odd` |
| `even` | `&:even` |
| `visited` | `&:visited` |
| `checked` | `&:checked` |
| `hover` | `&:hover` |
| `focus` | `&:focus` |
| `focusVisible` | `&:focus-visible` |
| `focusWithin` | `&:focus-within` |
| `active` | `&:active` |
| `disabled` | `&:disabled, &[aria-disabled=true]` |
| `placeholder` | `&::placeholder` |

## Customizing states

You can completely customize states in your theme:

```ts
export const theme = {
states: {
firstLetter: '&::first-letter',
dark: '.xstyled-color-mode-dark &&',
},
}
```

See the full docs for this feature [here](https://xstyled.dev/docs/hover-focus-other-states/).
2 changes: 1 addition & 1 deletion src/types/styled.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/addon-docs'

<Meta title='Exports/Types' />
<Meta title='Docs/Exports/Types' />

# Types

Expand Down
2 changes: 1 addition & 1 deletion src/utils/styled.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta } from '@storybook/addon-docs'

<Meta title='Exports/Utils' />
<Meta title='Docs/Exports/Utils' />

# Utils

Expand Down
2 changes: 1 addition & 1 deletion src/utils/theme.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Canvas } from 'core/storybookWrappers'

import defaultColors from 'constants/defaultColors.json'

<Meta title='Settings/Default Colors' />
<Meta title='Docs/Settings/Default Colors' />

# Changing Default Colors

Expand Down

0 comments on commit 696bf43

Please sign in to comment.