Skip to content

Commit

Permalink
Merge pull request #29 from TeamWertarbyte/breaking/muiv5-and-typescript
Browse files Browse the repository at this point in the history
feat: migrate to MUI v6

BREAKING CHANGE: Requires MUI v5 or v6
  • Loading branch information
saschb2b authored Sep 13, 2024
2 parents 3daa872 + 382aebe commit 0227408
Show file tree
Hide file tree
Showing 30 changed files with 2,958 additions and 10,267 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
33 changes: 33 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Check PR'

on:
pull_request_target:
types:
- opened
- synchronize
- reopened

jobs:
check-code:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint code
run: yarn lint
- name: Build library code
run: yarn build
check-versioning:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Create release'

on: [workflow_dispatch]

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint code
run: yarn lint
- name: Build library code
run: yarn build
- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
25 changes: 22 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
build
lib
coverage
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/*
node_modules

src/*
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"endOfLine": "auto"
}
9 changes: 9 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
"@semantic-release/npm"
]
}
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2020 Wertarbyte and contributors
Copyright (c) 2024 Wertarbyte and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Material-UI Dots

[![npm Package](https://img.shields.io/npm/v/material-ui-dots.svg)](https://www.npmjs.com/package/material-ui-dots)
[![Build Status](https://travis-ci.org/TeamWertarbyte/material-ui-dots.svg?branch=master)](https://travis-ci.org/TeamWertarbyte/material-ui-dots)
[![Coverage Status](https://coveralls.io/repos/github/TeamWertarbyte/material-ui-dots/badge.svg?branch=master)](https://coveralls.io/github/TeamWertarbyte/material-ui-dots?branch=next)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

This component gives you animated pagination dots as seen in the [Material Design specs][material-specs] and in the quick settings menu of Android N. The dots were extracted from our [auto-rotating carousel][material-auto-rotating-carousel] component.

Expand All @@ -12,33 +9,36 @@ This component gives you animated pagination dots as seen in the [Material Desig

## Installation
```shell
npm i --save material-ui-dots
yarn add material-ui-dots
```

## Usage

There is only a single `Dots` component which is to be used in controlled mode. The following example component will display five dots and select a dot when clicking on it.

```js
import React from 'react'
import Dots from 'material-ui-dots'

class Demo extends React.Component {
constructor (props) {
super(props)
this.state = { index: 0 }
}

render () {
return (
<Dots
index={this.state.index}
count={5}
onDotClick={(index) => this.setState({ index })}
/>
)
}
}
import * as React from 'react'
import { Dots } from 'material-ui-dots'
import { Box } from '@mui/material';

export const App: React.FC = () => {
const [index, setIndex] = React.useState<number>(0);

return (
<Box
sx={{
display: 'flex',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
borderRadius: 6,
pb: 0.5,
width: 200,
}}
>
<Dots index={index} count={5} onDotClick={(value) => setIndex(value)} />
</Box>
);
};
```

## License
Expand Down
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dots - React Material UI component</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
86 changes: 86 additions & 0 deletions lib/components/Dots/Dots.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React, { useEffect, useState } from 'react';
import Paper from '@mui/material/Paper';
import Box from '@mui/material/Box';
import { SxProps, Theme } from '@mui/material/styles';

interface DotsProps {
count: number;
index: number;
sx?: SxProps<Theme>;
onDotClick?: (
index: number,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => void;
}

export const Dots: React.FC<DotsProps> = ({ count, index, sx, onDotClick }) => {
const [previousIndex, setPreviousIndex] = useState<number>(index);

useEffect(() => {
if (index !== previousIndex) {
const timeout = setTimeout(() => {
setPreviousIndex(index);
}, 400);
return () => clearTimeout(timeout);
}
}, [index, previousIndex]);

const handleDotClick = (
dotIndex: number,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
if (onDotClick) {
onDotClick(dotIndex, event);
}
};

return (
<Box sx={{ width: count * 16, ...sx }}>
<Box sx={{ position: 'relative', padding: '20px 0 28px' }}>
{[...Array(count).keys()].map((i) => (
<Box
key={i}
sx={{
width: 8,
height: 8,
padding: 0.5,
position: 'absolute',
left: i * 16,
cursor: onDotClick ? 'pointer' : 'inherit',
}}
onClick={(event) => handleDotClick(i, event)}
>
<Paper
elevation={0}
sx={{
width: 8,
height: 8,
background: '#fff',
borderRadius: 4,
transition: 'all 400ms cubic-bezier(0.4, 0.0, 0.2, 1)',
opacity:
i >= Math.min(previousIndex, index) &&
i <= Math.max(previousIndex, index)
? 0
: 0.5,
}}
/>
</Box>
))}
<Paper
elevation={0}
sx={{
position: 'absolute',
marginTop: 0.5,
left: Math.min(previousIndex, index) * 16 + 4,
width: Math.abs(previousIndex - index) * 16 + 8,
height: 8,
background: '#fff',
borderRadius: 4,
transition: 'all 400ms cubic-bezier(0.4, 0.0, 0.2, 1)',
}}
/>
</Box>
</Box>
);
};
1 change: 1 addition & 0 deletions lib/components/Dots/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Dots.tsx';
1 change: 1 addition & 0 deletions lib/material-ui-dots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/Dots';
1 change: 1 addition & 0 deletions lib/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading

0 comments on commit 0227408

Please sign in to comment.