Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[base-ui] Create useNumberInput and NumberInput #36119

Merged
merged 70 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c3c9b97
[base] Add useNumberInput
mj12albert Feb 1, 2023
a8418f0
Add aria attributes, more types.
mj12albert Feb 27, 2023
c5f9b59
Add NumberInputUnstyled
mj12albert Feb 23, 2023
3a9b8f9
Redo change handlers
mj12albert Feb 28, 2023
fb52a63
Add increment and decrement buttons
mj12albert Mar 1, 2023
3e19da1
Keyboard handlers and shift multiplier
mj12albert Mar 2, 2023
40bee99
Apply code review changes
mj12albert Mar 3, 2023
df5b8e8
Extract number check util
mj12albert Mar 3, 2023
de0cb54
Separate directories
mj12albert Mar 3, 2023
39c1e2c
Update docs
mj12albert Mar 3, 2023
7fc5122
NumberInput introduction demo
mj12albert Mar 3, 2023
c508ec3
Store quantity picker demo
mj12albert Mar 9, 2023
fdf42c9
Add a demo using useNumberInput
mj12albert Mar 22, 2023
0734764
Update NumberInputUnstyled to support useClassNamesOverride
mj12albert Mar 22, 2023
e95f643
Add second hook demo
mj12albert Mar 23, 2023
b0ea58c
Fix compatibility with ComponentPageTabs
mj12albert Apr 12, 2023
23d9d36
Write docs page
mj12albert Apr 12, 2023
ce96976
Add explanation of min, max, step props
mj12albert Apr 12, 2023
e187960
Add explanation of shiftMultiplier prop
mj12albert Apr 13, 2023
7b733c5
Simplify hook demo
mj12albert Apr 17, 2023
e9267ff
Design revisions
mj12albert Apr 18, 2023
e424858
Format demos
mj12albert Apr 18, 2023
1a67068
Expand introduction paragraph
mj12albert Apr 19, 2023
1f8162f
Update onValueChange signature
mj12albert Apr 19, 2023
11bff81
Align dirty value updater naming
mj12albert Apr 21, 2023
188e02e
Remove Unstyled suffix
mj12albert Apr 28, 2023
8450b0b
Tweak stepping behavior
mj12albert May 1, 2023
e0c81e2
Add readOnly prop
mj12albert May 2, 2023
1b9ed63
Align with latest API changes
mj12albert May 11, 2023
dc6f1ee
Add tests
mj12albert May 15, 2023
8c8e8a8
Add onValueChange test
mj12albert May 15, 2023
7a774be
Add keyboard interaction tests
mj12albert May 15, 2023
e4a73d9
Add stepper button tests
mj12albert May 16, 2023
18868e4
Test out @testing-library/user-event
mj12albert May 17, 2023
b3161e6
Update keyboard interaction tests
mj12albert May 17, 2023
bef43f2
Add more stepper button tests
mj12albert May 17, 2023
64d459f
Refactor tests using user-event
mj12albert May 17, 2023
10e8c33
Improve tab order tests
mj12albert May 17, 2023
0f2b804
Cleanup
mj12albert May 18, 2023
e6c57a5
Remove spinbutton role, add aria-controls
mj12albert May 19, 2023
68b2641
Fix NumberInput test missing slots
mj12albert May 19, 2023
eb93cbb
A few visual tweaks on the Demos
zanivan May 22, 2023
bcf5a67
yarn docs:typescript:formatted
zanivan May 22, 2023
f5e8422
Add unstable prefix
mj12albert May 24, 2023
db39c57
Rename change handlers
mj12albert May 29, 2023
ccd3199
Add use-client
mj12albert Jul 26, 2023
63c0d44
Docs fixes
mj12albert Jul 26, 2023
6ba86c5
Add Tailwind and plain CSS versions of basic demo
mj12albert Jul 26, 2023
1058f01
Update intro demo
mj12albert Jul 27, 2023
b281e29
Update QuantityInput demo
mj12albert Jul 27, 2023
98d9217
Update CompactNumberInput demo
mj12albert Jul 27, 2023
7317788
Update hook demo
mj12albert Jul 28, 2023
8ea2349
Drop the component prop and single letter type names
mj12albert Jul 28, 2023
2ac68aa
Update api docs
mj12albert Jul 28, 2023
2563733
Generate proptypes
mj12albert Jul 28, 2023
fd7ba0d
Update api docs
mj12albert Jul 28, 2023
6ea8267
Update readOnly behavior
mj12albert Jul 31, 2023
b887e89
Fix generating import statements for unstable items in Base API pages
mj12albert Aug 1, 2023
3b9aac2
Fix arrows in NumberInputIntroduction
mj12albert Aug 1, 2023
19b5af2
Fix all html arrows in the demos
mj12albert Aug 1, 2023
087e442
Misc fixes
mj12albert Aug 1, 2023
9e545a0
Type onBlur more explicitly
mj12albert Aug 1, 2023
414442f
Update api docs
mj12albert Aug 1, 2023
105c8c1
Styling fixes for demos
mj12albert Aug 1, 2023
ca3b51b
More styling fixes
mj12albert Aug 1, 2023
25d8a68
Another styling fix
mj12albert Aug 2, 2023
652c650
Fix component import name
mj12albert Aug 2, 2023
087e1f2
Fix svg sizing in buttons for mobile Safari
mj12albert Aug 2, 2023
1735597
Fix variable names
mj12albert Aug 2, 2023
420053d
Change product to productId in md
mj12albert Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions docs/data/base/components/number-input/NumberInputBasic/css/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import * as React from 'react';
import NumberInput, { numberInputClasses } from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';

export default function NumberInputBasic() {
return (
<React.Fragment>
<NumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<Styles />
</React.Fragment>
);
}

const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};

const grey = {
50: '#F3F6F9',
100: '#E7EBF0',
200: '#E0E3E7',
300: '#CDD2D7',
400: '#B2BAC2',
500: '#A0AAB4',
600: '#6F7E8C',
700: '#3E5060',
800: '#2D3843',
900: '#1A2027',
};

function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}

function Styles() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();

return (
<style>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.5;
border-radius: 8px;
color: ${isDarkMode ? grey[300] : grey[900]};
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
}

.CustomNumberInput:hover {
border-color: ${cyan[400]};
}

.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}

.CustomNumberInput .input {
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: 0;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}

.CustomNumberInput .input:focus-visible {
outline: 0;
}

.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
line-height: 1;
background: ${isDarkMode ? grey[900] : '#fff'};
color: ${isDarkMode ? grey[300] : grey[900]};
border: 0;

transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}

.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}

.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
}

.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
}
`}
</style>
);
}
146 changes: 146 additions & 0 deletions docs/data/base/components/number-input/NumberInputBasic/css/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import * as React from 'react';
import NumberInput, { numberInputClasses } from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';

export default function NumberInputBasic() {
return (
<React.Fragment>
<NumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<Styles />
</React.Fragment>
);
}

const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};

const grey = {
50: '#F3F6F9',
100: '#E7EBF0',
200: '#E0E3E7',
300: '#CDD2D7',
400: '#B2BAC2',
500: '#A0AAB4',
600: '#6F7E8C',
700: '#3E5060',
800: '#2D3843',
900: '#1A2027',
};

function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}

function Styles() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();

return (
<style>
{`
.CustomNumberInput {
font-family: IBM Plex Sans, sans-serif;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.5;
border-radius: 8px;
color: ${isDarkMode ? grey[300] : grey[900]};
background: ${isDarkMode ? grey[900] : '#fff'};
border: 1px solid ${isDarkMode ? grey[700] : grey[200]};
box-shadow: 0px 2px 2px ${isDarkMode ? grey[900] : grey[50]};
display: grid;
grid-template-columns: 1fr 19px;
grid-template-rows: 1fr 1fr;
overflow: hidden;
}

.CustomNumberInput:hover {
border-color: ${cyan[400]};
}

.CustomNumberInput.${numberInputClasses.focused} {
border-color: ${cyan[400]};
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}

.CustomNumberInput .input {
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: inherit;
line-height: 1.5;
grid-column: 1/2;
grid-row: 1/3;
color: ${isDarkMode ? grey[300] : grey[900]};
background: inherit;
border: 0;
border-radius: inherit;
padding: 8px 12px;
outline: 0;
}

.CustomNumberInput .input:focus-visible {
outline: 0;
}

.CustomNumberInput .btn {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
appearance: none;
padding: 0;
width: 19px;
height: 19px;
font-family: system-ui, sans-serif;
font-size: 0.875rem;
box-sizing: border-box;
line-height: 1;
background: ${isDarkMode ? grey[900] : '#fff'};
color: ${isDarkMode ? grey[300] : grey[900]};
border: 0;

transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 120ms;
}

.CustomNumberInput .btn:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}

.CustomNumberInput .btn.increment {
grid-column: 2/3;
grid-row: 1/2;
}

.CustomNumberInput .btn.decrement {
grid-column: 2/3;
grid-row: 2/3;
}
`}
</style>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<React.Fragment>
<NumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
}}
aria-label="Demo number input"
placeholder="Type a number…"
/>
<Styles />
</React.Fragment>
Loading