Advertisement
REALAPROX

React radius slider preview

Jan 14th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. 'use client';
  2. import * as React from 'react';
  3. import { Box, FormLabel, Paper, Slider, Typography } from '@mui/material';
  4. import BorderStyleIcon from '@mui/icons-material/BorderStyle';
  5. import Tab from '@mui/material/Tab';
  6. import PropTypes from 'prop-types';
  7. import Tabs from '@mui/material/Tabs';
  8.  
  9. function CustomTabPanel(props: any) {
  10. const { children, value, index, ...other } = props;
  11.  
  12. return (
  13. <div
  14. role='tabpanel'
  15. hidden={value !== index}
  16. id={`simple-tabpanel-${index}`}
  17. aria-labelledby={`simple-tab-${index}`}
  18. {...other}>
  19. {value === index && (
  20. <Box sx={{ p: 3 }}>
  21. <Typography>{children}</Typography>
  22. </Box>
  23. )}
  24. </div>
  25. );
  26. }
  27.  
  28. CustomTabPanel.propTypes = {
  29. children: PropTypes.node,
  30. index: PropTypes.number.isRequired,
  31. value: PropTypes.number.isRequired,
  32. };
  33.  
  34. //@ts-ignore
  35. function a11yProps(index) {
  36. return {
  37. id: `simple-tab-${index}`,
  38. 'aria-controls': `simple-tabpanel-${index}`,
  39. };
  40. }
  41.  
  42. const BorderRadius = () => {
  43. const [value, setValue] = React.useState(0);
  44. const [simpleRadius, setSimpleRadius] = React.useState(0);
  45.  
  46. //@ts-ignore
  47. const handleChange = (event, newValue) => {
  48. setValue(newValue);
  49. };
  50.  
  51. //styles
  52. const paperClass = {
  53. '&.MuiPaper-root': {
  54. backgroundImage: 'unset',
  55. backgroundColor: '#202025',
  56. },
  57. display: 'flex',
  58. flexDirection: 'column',
  59. justifyContent: 'center',
  60. width: 2 / 3,
  61. maxWidth: 'md',
  62. padding: 2,
  63. gap: 2,
  64. };
  65.  
  66. const tabBoxClass = {
  67. borderBottom: 1,
  68. borderColor: 'divider',
  69. display: 'flex',
  70. gap: 0,
  71. };
  72.  
  73. const tabStyleClass = {
  74. flexGrow: 1,
  75. m: 0,
  76. };
  77.  
  78. const panelBoxClass = {
  79. width: '100%',
  80. height: 'auto',
  81. aspectRatio: '1/1',
  82. display: 'flex',
  83. flexDirection: 'column',
  84. alignItems: 'start',
  85. gap: 2,
  86. };
  87.  
  88. const interactiveBoxHolderClass = {
  89. width: '100%',
  90. height: 'auto',
  91. aspectRatio: '1/1',
  92. border: '1px dashed grey',
  93. flexGrow: 1,
  94. display: 'flex',
  95. flexDirection: 'column',
  96. alignItems: 'center',
  97. justifyContent: 'center',
  98. gap: 1,
  99. Typography: 'body1',
  100. py:0,
  101. m:0,
  102. };
  103.  
  104. const sliderClass = {
  105. maxWidth: '240px',
  106. };
  107.  
  108. const simpleRadiusBox = {
  109. width: 2 / 3,
  110. height: 'auto',
  111. aspectRatio: '1/1',
  112. borderRadius: `${simpleRadius}%`,
  113. bgcolor: 'info.light',
  114. '&:hover': {
  115. bgcolor: 'info.main',
  116. },
  117. }
  118.  
  119. //@ts-ignore
  120. const valueText = (value) => {
  121. setSimpleRadius(value);
  122. return `${value}`;
  123. };
  124.  
  125. return (
  126. <div className='tw-flex-1 tw-grow tw-flex tw-flex-col tw-items-center tw-pt-24'>
  127. <Paper component='form' sx={paperClass} elevation={8}>
  128. <Box>
  129. <Typography
  130. variant='h5'
  131. sx={{
  132. textTransform: 'uppercase',
  133. display: 'flex',
  134. flexDirection: 'row',
  135. alignItems: 'center',
  136. gap: 1,
  137. }}
  138. gutterBottom>
  139. <BorderStyleIcon />
  140. Border Radius
  141. </Typography>
  142. <Typography variant='subtitle1' gutterBottom>
  143. Adjust box border radius
  144. </Typography>
  145. </Box>
  146.  
  147. <Box>
  148. <Tabs
  149. centered
  150. value={value}
  151. onChange={handleChange}
  152. aria-label='basic tabs example'
  153. sx={tabBoxClass}>
  154. <Tab sx={tabStyleClass} label='Simple' {...a11yProps(0)} />
  155. <Tab sx={tabStyleClass} label='Advanced' {...a11yProps(1)} />
  156. </Tabs>
  157.  
  158. <CustomTabPanel value={value} index={0}>
  159. <Box sx={panelBoxClass}>
  160. <Box
  161. sx={{
  162. width: '100%',
  163. display: 'flex',
  164. flexDirection: 'column',
  165. gap: 2,
  166. }}>
  167. <FormLabel>
  168. Simple radius adjustment.
  169. </FormLabel>
  170. <Slider
  171. sx={sliderClass}
  172. name='simpleRadiusSlider'
  173. aria-label='Radius'
  174. defaultValue={12}
  175. getAriaValueText={valueText}
  176. valueLabelDisplay='auto'
  177. step={1}
  178. min={0}
  179. max={50}
  180. />
  181. </Box>
  182.  
  183. <Box component='section' sx={interactiveBoxHolderClass}>
  184. <FormLabel
  185. sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
  186. Radius: {simpleRadius}%
  187. </FormLabel>
  188. <Box sx={simpleRadiusBox}></Box>
  189. </Box>
  190. </Box>
  191. </CustomTabPanel>
  192.  
  193. <CustomTabPanel value={value} index={1}>
  194. Advanced controls
  195. </CustomTabPanel>
  196. </Box>
  197. </Paper>
  198. </div>
  199. );
  200. };
  201.  
  202. export default BorderRadius;
  203.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement