import { ArgsTable, Preview, Story } from '@storybook/addon-docs/blocks';
import { createTheme, Media } from '../../..';

export const theme = createTheme();

# Media

<Preview>
  <Story id="utilities-media--basic-usage" />
</Preview>

The `Media` component is used to show and hide components depending on the screen size using media queries.
It's to be used with `theme.breakpoints` that are based on device size widths.

## Media queries

The `Media` component uses theme functions and breakpoints to create media queries.
The `theme.media` has three functions that are to be used with breakpoints.

- `greaterThan`: The component is shown above a certain breakpoint
- `lessThan`: The component is shown below a certain breakpoint
- `between`: The component is shown between two breakpoints

These can be used in conjunction with a set of breakpoints

<table>
  <thead>
    <tr>
      <th>Breakpoint</th>
      <th>Min width</th>
    </tr>
  </thead>
  <tbody>
    <>
      <tr>
        <td>xs</td>
        <td>300px</td>
      </tr>
      {Object.keys(theme.breakpoints).map((breakpointKey) => {
        const width = theme.breakpoints[breakpointKey];
        return (
          <tr>
            <td>{breakpointKey}</td>
            <td>{width}px</td>
          </tr>
        );
      })}
    </>
  </tbody>
</table>

## Hook

The `Media` component uses the `useMedia` hook. You can access this hook directly to
set values depending on screen size, rather than just hiding or showing a component.

<Preview>
  <Story id="utilities-media--hook-usage" />
</Preview>

## Props

<ArgsTable of={Media} />
