From e3952a541b4ddbb9da36e7474a684c1df75774e8 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sat, 1 Feb 2020 20:45:11 +0100 Subject: [PATCH] [docs] Add SwipeableTextMobileStepper demo (#18503) --- docs/package.json | 1 + .../steppers/SwipeableTextMobileStepper.tsx | 122 ++++++++++++++++++ yarn.lock | 13 +- 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 docs/src/pages/components/steppers/SwipeableTextMobileStepper.tsx diff --git a/docs/package.json b/docs/package.json index b065c43b598aa0..d568b40a540795 100644 --- a/docs/package.json +++ b/docs/package.json @@ -40,6 +40,7 @@ "@types/react-dom": "^16.9.1", "@types/react-router-dom": "^5.1.0", "@types/react-swipeable-views": "^0.13.0", + "@types/react-swipeable-views-utils": "^0.13.0", "@types/react-text-mask": "^5.4.6", "@types/react-virtualized": "^9.21.4", "@types/react-window": "^1.7.0", diff --git a/docs/src/pages/components/steppers/SwipeableTextMobileStepper.tsx b/docs/src/pages/components/steppers/SwipeableTextMobileStepper.tsx new file mode 100644 index 00000000000000..647af09b9df5d3 --- /dev/null +++ b/docs/src/pages/components/steppers/SwipeableTextMobileStepper.tsx @@ -0,0 +1,122 @@ +import React from 'react'; +import { makeStyles, useTheme } from '@material-ui/core/styles'; +import MobileStepper from '@material-ui/core/MobileStepper'; +import Paper from '@material-ui/core/Paper'; +import Typography from '@material-ui/core/Typography'; +import Button from '@material-ui/core/Button'; +import KeyboardArrowLeft from '@material-ui/icons/KeyboardArrowLeft'; +import KeyboardArrowRight from '@material-ui/icons/KeyboardArrowRight'; +import SwipeableViews from 'react-swipeable-views'; +import { autoPlay } from 'react-swipeable-views-utils'; + +const AutoPlaySwipeableViews = autoPlay(SwipeableViews); + +const tutorialSteps = [ + { + label: 'San Francisco – Oakland Bay Bridge, United States', + imgPath: + 'https://images.unsplash.com/photo-1537944434965-cf4679d1a598?auto=format&fit=crop&w=400&h=250&q=60', + }, + { + label: 'Bird', + imgPath: + 'https://images.unsplash.com/photo-1538032746644-0212e812a9e7?auto=format&fit=crop&w=400&h=250&q=60', + }, + { + label: 'Bali, Indonesia', + imgPath: + 'https://images.unsplash.com/photo-1537996194471-e657df975ab4?auto=format&fit=crop&w=400&h=250&q=80', + }, + { + label: 'NeONBRAND Digital Marketing, Las Vegas, United States', + imgPath: + 'https://images.unsplash.com/photo-1518732714860-b62714ce0c59?auto=format&fit=crop&w=400&h=250&q=60', + }, + { + label: 'Goč, Serbia', + imgPath: + 'https://images.unsplash.com/photo-1512341689857-198e7e2f3ca8?auto=format&fit=crop&w=400&h=250&q=60', + }, +]; + +const useStyles = makeStyles(theme => ({ + root: { + maxWidth: 400, + flexGrow: 1, + }, + header: { + display: 'flex', + alignItems: 'center', + height: 50, + paddingLeft: theme.spacing(4), + backgroundColor: theme.palette.background.default, + }, + img: { + height: 255, + display: 'block', + maxWidth: 400, + overflow: 'hidden', + width: '100%', + }, +})); + +function SwipeableTextMobileStepper() { + const classes = useStyles(); + const theme = useTheme(); + const [activeStep, setActiveStep] = React.useState(0); + const maxSteps = tutorialSteps.length; + + const handleNext = () => { + setActiveStep(prevActiveStep => prevActiveStep + 1); + }; + + const handleBack = () => { + setActiveStep(prevActiveStep => prevActiveStep - 1); + }; + + const handleStepChange = (step: number) => { + setActiveStep(step); + }; + + return ( +
+ + {tutorialSteps[activeStep].label} + + + {tutorialSteps.map((step, index) => ( +
+ {Math.abs(activeStep - index) <= 2 ? ( + {step.label} + ) : null} +
+ ))} +
+ + Next + {theme.direction === 'rtl' ? : } + + } + backButton={ + + } + /> +
+ ); +} + +export default SwipeableTextMobileStepper; diff --git a/yarn.lock b/yarn.lock index ac7ca950a62a80..6929a6cb88ba7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1807,7 +1807,7 @@ loose-envify "^1.4.0" prop-types "^15.6.2" -"@material-ui/types@^4.1.1": +"@material-ui/types@^4.0.0", "@material-ui/types@^4.1.1": version "4.1.1" resolved "https://registry.yarnpkg.com/@material-ui/types/-/types-4.1.1.tgz#b65e002d926089970a3271213a3ad7a21b17f02b" integrity sha512-AN+GZNXytX9yxGi0JOfxHrRTbhFybjUJ05rnsBVjcB+16e466Z0Xe5IxawuOayVZgTBNDxmPKo5j4V6OnMtaSQ== @@ -2234,7 +2234,16 @@ "@types/history" "*" "@types/react" "*" -"@types/react-swipeable-views@^0.13.0": +"@types/react-swipeable-views-utils@^0.13.0": + version "0.13.0" + resolved "https://registry.yarnpkg.com/@types/react-swipeable-views-utils/-/react-swipeable-views-utils-0.13.0.tgz#d65650e177d25df3b9c1d5c059b5252525b04e6e" + integrity sha512-NhMLpJLCrZ61Ybdk4K3mDi0me6lrYtriu1o+J7N+mSc5pxbtZX1cqm2J2CLdz0WnGbJ4WeW2U/w6CLXBxg8VHw== + dependencies: + "@material-ui/types" "^4.0.0" + "@types/react" "*" + "@types/react-swipeable-views" "*" + +"@types/react-swipeable-views@*", "@types/react-swipeable-views@^0.13.0": version "0.13.0" resolved "https://registry.yarnpkg.com/@types/react-swipeable-views/-/react-swipeable-views-0.13.0.tgz#9e5f2efa51380886f3f73014ac8b15546d337210" integrity sha512-orrreCcXev6IUXDuHf07RDDCAoIZRMSr95eyWmYNRfjic7w/O+68iPu0NCysVls+UygRNvoqZMuXI72N/58E1w==