├── .eslintrc.json ├── .gitignore ├── .prettierrc.json ├── README.md ├── next.config.js ├── package-lock.json ├── package.json ├── pages ├── _app.tsx └── index.tsx ├── postcss.config.js ├── public ├── favicon.ico └── vercel.svg ├── styles └── globals.css ├── tailwind.config.js └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | ``` 12 | 13 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 14 | 15 | You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. 16 | 17 | [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. 18 | 19 | The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | swcMinify: true, 5 | } 6 | 7 | module.exports = nextConfig 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "2022-12-07-ios-16-slider", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@heroicons/react": "^2.0.13", 13 | "@types/node": "18.11.11", 14 | "@types/react": "18.0.26", 15 | "@types/react-dom": "18.0.9", 16 | "eslint": "8.29.0", 17 | "eslint-config-next": "13.0.6", 18 | "framer-motion": "^7.6.19", 19 | "next": "13.0.6", 20 | "react": "18.2.0", 21 | "react-dom": "18.2.0", 22 | "react-use-measure": "^2.1.1", 23 | "typescript": "4.9.3" 24 | }, 25 | "devDependencies": { 26 | "autoprefixer": "^10.4.13", 27 | "postcss": "^8.4.19", 28 | "prettier": "2.8.1", 29 | "tailwindcss": "^3.2.4" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css' 2 | import type { AppProps } from 'next/app' 3 | 4 | export default function App({ Component, pageProps }: AppProps) { 5 | return 6 | } 7 | -------------------------------------------------------------------------------- /pages/index.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | motion, 3 | MotionConfig, 4 | useMotionValue, 5 | useTransform, 6 | } from "framer-motion"; 7 | import { useEffect, useState } from "react"; 8 | import useMeasure from "react-use-measure"; 9 | import { SpeakerWaveIcon, SpeakerXMarkIcon } from "@heroicons/react/20/solid"; 10 | 11 | export default function Page() { 12 | let initialHeight = 4; 13 | let height = 12; 14 | let buffer = 12; 15 | let [ref, bounds] = useMeasure(); 16 | let [hovered, setHovered] = useState(false); 17 | let [panning, setPanning] = useState(false); 18 | let progress = useMotionValue(0.5); 19 | let width = useTransform(progress, (v) => `${v * 100}%`); 20 | let roundedProgress = useTransform( 21 | progress, 22 | (v) => `${roundTo(v * 100, 0)}%` 23 | ); 24 | let [progressState, setProgressState] = useState(roundedProgress.get()); 25 | let state = panning ? "panning" : hovered ? "hovered" : "idle"; 26 | 27 | useEffect(() => { 28 | roundedProgress.onChange((v) => setProgressState(v)); 29 | }, [roundedProgress]); 30 | 31 | return ( 32 | 33 |
34 |
35 |

36 | iOS 16 Slider demo 37 |

38 |
39 |
40 | 50 | 51 | 52 | {/* Slider */} 53 | setPanning(true)} 56 | onPanEnd={() => setPanning(false)} 57 | onPointerEnter={() => setHovered(true)} 58 | onPointerLeave={() => setHovered(false)} 59 | onPan={(event, info) => { 60 | let deltaInPercent = info.delta.x / bounds.width; 61 | let newPercent = clamp(progress.get() + deltaInPercent, 0, 1); 62 | progress.set(newPercent); 63 | }} 64 | style={{ height: height + buffer }} 65 | className="flex items-center justify-center relative touch-none grow-0" 66 | variants={{ 67 | idle: { width: "calc(95% - 48px)" }, 68 | hovered: { width: "calc(100% - 48px)" }, 69 | panning: { width: "calc(100% - 48px)" }, 70 | }} 71 | initial={false} 72 | ref={ref} 73 | > 74 | 83 |
84 | 88 | 89 | 90 | 100 | 101 | 102 |
103 | {/* Label */} 104 | 112 | {progressState} 113 | 114 |
115 |
116 |
117 | 118 | ); 119 | } 120 | 121 | let transition = { type: "spring", bounce: 0, duration: 0.3 }; 122 | 123 | let clamp = (num: number, min: number, max: number) => 124 | Math.max(Math.min(num, max), min); 125 | 126 | function roundTo(number: number, decimals: number): number { 127 | return Math.round(number * Math.pow(10, decimals)) / Math.pow(10, decimals); 128 | } 129 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samselikoff/2022-12-07-ios-16-slider/13ee27fa546d1ea37c62cab400595ce88f8d10dd/public/favicon.ico -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /styles/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | html { 6 | @apply antialiased bg-black text-gray-100 7 | } 8 | 9 | html, body, #__next { 10 | @apply h-full 11 | } -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const colors = require('tailwindcss/colors') 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | module.exports = { 5 | content: [ 6 | "./pages/**/*.{js,ts,jsx,tsx}", 7 | "./components/**/*.{js,ts,jsx,tsx}", 8 | ], 9 | theme: { 10 | extend: { 11 | colors: { 12 | gray: colors.stone 13 | } 14 | }, 15 | }, 16 | plugins: [], 17 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true 17 | }, 18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 19 | "exclude": ["node_modules"] 20 | } 21 | --------------------------------------------------------------------------------