|
| 1 | +# Responsive |
| 2 | + |
| 3 | +Devup UI supports responsive design. |
| 4 | + |
| 5 | +# Breakpoints |
| 6 | + |
| 7 | +Devup UI provides flexible responsive design capabilities through breakpoints. You can use either the default breakpoint system or customize your own breakpoints to match your design requirements. |
| 8 | + |
| 9 | +## Default Breakpoints |
| 10 | + |
| 11 | +By default, Devup UI uses a 5-breakpoint system with the following viewport ranges: |
| 12 | + |
| 13 | +| Index | Viewport Range | Description | |
| 14 | +| ----- | -------------- | --------------- | |
| 15 | +| 1st | ~ 479px | Mobile (small) | |
| 16 | +| 2nd | 480px ~ 767px | Mobile (large) | |
| 17 | +| 3rd | 768px ~ 991px | Tablet | |
| 18 | +| 4th | 992px ~ 1279px | Desktop (small) | |
| 19 | +| 5th | 1280px ~ | Desktop (large) | |
| 20 | + |
| 21 | +## Using Responsive Arrays |
| 22 | + |
| 23 | +You can add responsive design by using an array of maximum 5 elements for any style property: |
| 24 | + |
| 25 | +```jsx |
| 26 | +const box = ( |
| 27 | + <Box bg={["red", "blue", "green", "yellow", "purple"]} w={25} h={25}> |
| 28 | + <Text>Hello</Text> |
| 29 | + </Box> |
| 30 | +); |
| 31 | +``` |
| 32 | + |
| 33 | +### Null Values |
| 34 | + |
| 35 | +If any of the five elements are set to `null`, Devup UI uses the previous value for responsive design: |
| 36 | + |
| 37 | +```jsx |
| 38 | +// Background will be: |
| 39 | +// - red from 0px to 767px (1st and 2nd breakpoints) |
| 40 | +// - green from 768px to 1279px (3rd and 4th breakpoints) |
| 41 | +// - purple from 1280px and above (5th breakpoint) |
| 42 | +<Box bg={["red", null, "green", null, "purple"]} /> |
| 43 | +``` |
| 44 | + |
| 45 | +### Partial Arrays |
| 46 | + |
| 47 | +If the length of the array is less than 5, Devup UI makes responsive design according to the index of the element: |
| 48 | + |
| 49 | +```jsx |
| 50 | +// Only specify mobile and desktop values |
| 51 | +<Box bg={['red', 'blue']} /> // red for mobile, blue for larger screens |
| 52 | + |
| 53 | +// Specify mobile, tablet, and desktop |
| 54 | +<Box bg={['red', 'blue', 'green']} /> |
| 55 | +``` |
| 56 | + |
| 57 | +## Custom Breakpoints |
| 58 | + |
| 59 | +You can customize breakpoints by adding a `breakpoints` configuration to your `devup.json` file: |
| 60 | + |
| 61 | +### Configuration |
| 62 | + |
| 63 | +```json |
| 64 | +{ |
| 65 | + "theme": { |
| 66 | + "breakpoints": [0, 460, 768, 1024] |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### How Custom Breakpoints Work |
| 72 | + |
| 73 | +When you define custom breakpoints, the array values correspond to minimum viewport widths: |
| 74 | + |
| 75 | +- **1st element**: From 0px to the first breakpoint value |
| 76 | +- **2nd element**: From first breakpoint to second breakpoint |
| 77 | +- **3rd element**: From second breakpoint to third breakpoint |
| 78 | +- **And so on...** |
| 79 | + |
| 80 | +### Example with Custom Breakpoints |
| 81 | + |
| 82 | +```json |
| 83 | +// create devup.json |
| 84 | +{ |
| 85 | + "theme": { |
| 86 | + "breakpoints": [0, 460, 1024] |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +```jsx |
| 92 | +// With the custom breakpoints above: |
| 93 | +<Box bg={["red", "blue", "green"]} /> |
| 94 | +``` |
| 95 | + |
| 96 | +This would create the following responsive behavior: |
| 97 | + |
| 98 | +- `red` background from 0px to 459px |
| 99 | +- `blue` background from 460px to 1023px |
| 100 | +- `green` background from 1024px and above |
0 commit comments