Skip to content

Commit

Permalink
Merge branch 'master' into refactor-textareaautosize-and-fix-40557
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeshanTamboli committed Jan 30, 2024
2 parents 790222b + c479c9b commit dc3a73d
Show file tree
Hide file tree
Showing 162 changed files with 3,727 additions and 2,370 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/examples/material-ui-nextjs/src
/packages/mui-codemod/lib
/packages/mui-codemod/src/*/*.test/*
/packages/mui-codemod/src/**/test-cases/*
/packages/mui-icons-material/fixtures
/packages/mui-icons-material/legacy
/packages/mui-icons-material/lib
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
uses: github/codeql-action/init@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
with:
languages: typescript
config-file: ./.github/codeql/codeql-config.yml
Expand All @@ -30,4 +30,4 @@ jobs:
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
uses: github/codeql-action/analyze@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
2 changes: 1 addition & 1 deletion .github/workflows/issue-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
permissions:
issues: write
steps:
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const issue = await github.rest.issues.get({
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/priority-support-validation-prompt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Find Comment
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1 # v2
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3
id: findComment
with:
issue-number: ${{ github.event.issue.number }}
Expand All @@ -25,7 +25,7 @@ jobs:

- name: Create comment
if: ${{ steps.findComment.outputs.comment-id == '' && contains(github.event.label.name, 'unknown') }}
uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ github.event.issue.number }}
body: |
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Update comment
if: ${{ steps.findComment.outputs.comment-id != '' && contains(github.event.label.name, 'priority') }}
uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.findComment.outputs.comment-id }}
body: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: Upload to code-scanning
uses: github/codeql-action/upload-sarif@0b21cf2492b6b02c465a3e5d7c473717ad7721ba # v3.23.1
uses: github/codeql-action/upload-sarif@b7bf0a3ed3ecfa44160715d7c442788f65f0f923 # v3.23.2
with:
sarif_file: results.sarif
4 changes: 3 additions & 1 deletion .markdownlint-cli2.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const straightQuotes = require('./packages/markdownlint-rule-mui/straight-quotes
const gitDiff = require('./packages/markdownlint-rule-mui/git-diff');
const tableAlignment = require('./packages/markdownlint-rule-mui/table-alignment');
const terminalLanguage = require('./packages/markdownlint-rule-mui/terminal-language');
const duplicateH1 = require('./packages/markdownlint-rule-mui/duplicate-h1');

// https://github.com/DavidAnson/markdownlint#rules--aliases
module.exports = {
Expand Down Expand Up @@ -35,8 +36,9 @@ module.exports = {
gitDiff: true,
tableAlignment: true,
terminalLanguage: true,
duplicateH1: true,
},
customRules: [straightQuotes, gitDiff, tableAlignment, terminalLanguage],
customRules: [straightQuotes, gitDiff, tableAlignment, terminalLanguage, duplicateH1],
ignores: [
'CHANGELOG.old.md',
'**/node_modules/**',
Expand Down
2 changes: 1 addition & 1 deletion apps/zero-runtime-vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/preset-env": "^7.23.8",
"@babel/preset-env": "^7.23.9",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@mui/material": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"styled-components": "^6.1.8",
"styled-system": "^5.1.5",
"theme-ui": "^0.16.1",
"webpack": "^5.89.0"
"webpack": "^5.90.0"
}
}
231 changes: 231 additions & 0 deletions docs/data/base/components/input/OTPInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Input as BaseInput } from '@mui/base/Input';
import { Box, styled } from '@mui/system';

function OTP({ separator, length, value, onChange }) {
const inputRefs = React.useRef(new Array(length).fill(null));

const focusInput = (targetIndex) => {
const targetInput = inputRefs.current[targetIndex];
targetInput.focus();
};

const selectInput = (targetIndex) => {
const targetInput = inputRefs.current[targetIndex];
targetInput.select();
};

const handleKeyDown = (event, currentIndex) => {
switch (event.key) {
case 'ArrowUp':
case 'ArrowDown':
case ' ':
event.preventDefault();
break;
case 'ArrowLeft':
event.preventDefault();
if (currentIndex > 0) {
focusInput(currentIndex - 1);
selectInput(currentIndex - 1);
}
break;
case 'ArrowRight':
event.preventDefault();
if (currentIndex < length - 1) {
focusInput(currentIndex + 1);
selectInput(currentIndex + 1);
}
break;
case 'Delete':
event.preventDefault();
onChange((prevOtp) => {
const otp =
prevOtp.slice(0, currentIndex) + prevOtp.slice(currentIndex + 1);
return otp;
});

break;
case 'Backspace':
event.preventDefault();
if (currentIndex > 0) {
focusInput(currentIndex - 1);
selectInput(currentIndex - 1);
}

onChange((prevOtp) => {
const otp =
prevOtp.slice(0, currentIndex) + prevOtp.slice(currentIndex + 1);
return otp;
});
break;

default:
break;
}
};

const handleChange = (event, currentIndex) => {
const currentValue = event.target.value;
let indexToEnter = 0;

while (indexToEnter <= currentIndex) {
if (inputRefs.current[indexToEnter].value && indexToEnter < currentIndex) {
indexToEnter += 1;
} else {
break;
}
}
onChange((prev) => {
const otpArray = prev.split('');
const lastValue = currentValue[currentValue.length - 1];
otpArray[indexToEnter] = lastValue;
return otpArray.join('');
});
if (currentValue !== '') {
if (currentIndex < length - 1) {
focusInput(currentIndex + 1);
}
}
};

const handleClick = (event, currentIndex) => {
selectInput(currentIndex);
};

const handlePaste = (event, currentIndex) => {
event.preventDefault();
const clipboardData = event.clipboardData;

// Check if there is text data in the clipboard
if (clipboardData.types.includes('text/plain')) {
let pastedText = clipboardData.getData('text/plain');
pastedText = pastedText.substring(0, length).trim();
let indexToEnter = 0;

while (indexToEnter <= currentIndex) {
if (inputRefs.current[indexToEnter].value && indexToEnter < currentIndex) {
indexToEnter += 1;
} else {
break;
}
}

const otpArray = value.split('');

for (let i = indexToEnter; i < length; i += 1) {
const lastValue = pastedText[i - indexToEnter] ?? ' ';
otpArray[i] = lastValue;
}

onChange(otpArray.join(''));
}
};

return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
{new Array(length).fill(null).map((_, index) => (
<React.Fragment key={index}>
<BaseInput
slots={{
input: InputElement,
}}
aria-label={`Digit ${index + 1} of OTP`}
slotProps={{
input: {
ref: (ele) => {
inputRefs.current[index] = ele;
},
onKeyDown: (event) => handleKeyDown(event, index),
onChange: (event) => handleChange(event, index),
onClick: (event) => handleClick(event, index),
onPaste: (event) => handlePaste(event, index),
value: value[index] ?? '',
},
}}
/>
{index === length - 1 ? null : separator}
</React.Fragment>
))}
</Box>
);
}

OTP.propTypes = {
length: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
separator: PropTypes.node,
value: PropTypes.string.isRequired,
};

export default function OTPInput() {
const [otp, setOtp] = React.useState('');

return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
}}
>
<OTP separator={<span>-</span>} value={otp} onChange={setOtp} length={5} />
<span>Entered value: {otp}</span>
</Box>
);
}

const blue = {
100: '#DAECFF',
200: '#80BFFF',
400: '#3399FF',
500: '#007FFF',
600: '#0072E5',
700: '#0059B2',
};

const grey = {
50: '#F3F6F9',
100: '#E5EAF2',
200: '#DAE2ED',
300: '#C7D0DD',
400: '#B0B8C4',
500: '#9DA8B7',
600: '#6B7A90',
700: '#434D5B',
800: '#303740',
900: '#1C2025',
};

const InputElement = styled('input')(
({ theme }) => `
width: 40px;
font-family: 'IBM Plex Sans', sans-serif;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.5;
padding: 8px 0px;
border-radius: 8px;
text-align: center;
color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]};
background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'};
border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]};
box-shadow: 0px 2px 4px ${
theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)'
};
&:hover {
border-color: ${blue[400]};
}
&:focus {
border-color: ${blue[400]};
box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]};
}
// firefox
&:focus-visible {
outline: 0;
}
`,
);
Loading

0 comments on commit dc3a73d

Please sign in to comment.