-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs[197]: useResponsiveValue documentation (#3344)
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@marigold/docs": patch | ||
--- | ||
|
||
docs[197]: useResponsiveValue documentation |
13 changes: 13 additions & 0 deletions
13
docs/content/hooks-and-utils/useResponsiveValue/tailwind-screen-size-with-hook.demo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useResponsiveValue } from '@marigold/system'; | ||
|
||
export default () => { | ||
const value = useResponsiveValue( | ||
['no breakpoint', 'sm', 'md', 'lg', 'xl', '2xl'], | ||
2 | ||
); | ||
return ( | ||
<div className="sm:bg-lime-600 md:bg-lime-500 lg:bg-lime-400 xl:bg-lime-300 2xl:bg-lime-200"> | ||
{value} | ||
</div> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
docs/content/hooks-and-utils/useResponsiveValue/useResponsiveValue.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: useResponsiveValue | ||
caption: Hook that returns values based on screen sizes. | ||
badge: updated | ||
--- | ||
|
||
The `useResponsiveValue` is a client side hook. It can be used to return values based on the current screen size, using breakpoints from the theme `theme.screens`. | ||
|
||
To add breakpoints to your theme you have to write them as an array. | ||
You can pass the following parameters to your useResponsiveValue hook: | ||
|
||
The first parameter of the hook will be the values as array which defines the breakpoints. The second argument must be the `defaultIndex` which points opn the default value. | ||
|
||
If you want to have a look on all possible breakpoints from the theme you can have a look [here](../introduction/design-tokens#breakpoints). | ||
|
||
Also with Tailwind some new class names came along which you can use to add styles by using the responsive modifiers (like: sm:text-sm). | ||
|
||
## Usage | ||
|
||
### Import | ||
|
||
To import the hook you just have to use this code below. | ||
|
||
```tsx | ||
import { useResponsiveValue } from '@marigold/system'; | ||
``` | ||
|
||
## Examples | ||
|
||
With the use of Tailwind CSS, some classes came along with which makes it easy to use different styles on different screen sizes. Here you can see a combination of the `useResponsiveValue` hook and the Tailwind screen sizes. | ||
|
||
For example if you want to change `background-color` for different screen sizes you have to use this code below. | ||
You can see that according to the screen size the text value will change. You can try out yourself and resize the screen. | ||
|
||
<ComponentDemo file="./tailwind-screen-size-with-hook.demo.tsx" /> | ||
|
||
### useSmallScreen | ||
|
||
We also have a function that checks if the window is on a small screen size. This can be used if you just want to change something just on small screen size. | ||
|
||
The example code shows that when it is a small screen the display css value will change. | ||
|
||
```tsx | ||
import { useSmallScreen } from '@marigold/system'; | ||
|
||
const isSmallScreen = useSmallScreen(); | ||
... | ||
<div className={cn(isSmallScreen ? 'hidden' : 'block')}>random div</div> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6f4953b
There was a problem hiding this comment.
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:
marigold-docs – ./
marigold-docs-marigold.vercel.app
marigold-docs.vercel.app
marigold-docs-git-main-marigold.vercel.app
6f4953b
There was a problem hiding this comment.
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:
marigold-storybook – ./
marigold-storybook-git-main-marigold.vercel.app
marigold-latest.vercel.app
marigold-storybook-marigold.vercel.app