Skip to content

Commit

Permalink
[docs][base] Add Tailwind CSS + plain CSS demo on the NumberInput page (
Browse files Browse the repository at this point in the history
  • Loading branch information
alisasanib authored Sep 16, 2023
1 parent 1cb83a5 commit 2843305
Show file tree
Hide file tree
Showing 15 changed files with 703 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ export default function NumberInputBasic() {
<NumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
input: { className: 'CustomNumberInput-input' },
decrementButton: {
className: 'CustomNumberInput-button CustomNumberInput-decrementButton',
children: '▾',
},
incrementButton: {
className: 'CustomNumberInput-button CustomNumberInput-incrementButton',
children: '▴',
},
}}
aria-label="Demo number input"
placeholder="Type a number…"
Expand Down Expand Up @@ -86,7 +92,7 @@ function Styles() {
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
.CustomNumberInput .input {
.CustomNumberInput .CustomNumberInput-input {
font-family: inherit;
font-size: inherit;
font-weight: inherit;
Expand All @@ -102,11 +108,11 @@ function Styles() {
outline: 0;
}
.CustomNumberInput .input:focus-visible {
.CustomNumberInput .CustomNumberInput-input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
.CustomNumberInput .CustomNumberInput-button {
display: flex;
flex-flow: row nowrap;
justify-content: center;
Expand All @@ -128,18 +134,18 @@ function Styles() {
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
.CustomNumberInput .CustomNumberInput-button:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
.CustomNumberInput .CustomNumberInput-button.CustomNumberInput-incrementButton {
grid-column: 2/3;
grid-row: 1/2;
}
.CustomNumberInput .btn.decrement {
.CustomNumberInput .CustomNumberInput-button.CustomNumberInput-decrementButton {
grid-column: 2/3;
grid-row: 2/3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ export default function NumberInputBasic() {
<NumberInput
slotProps={{
root: { className: 'CustomNumberInput' },
input: { className: 'input' },
decrementButton: { className: 'btn decrement', children: '▾' },
incrementButton: { className: 'btn increment', children: '▴' },
input: { className: 'CustomNumberInput-input' },
decrementButton: {
className: 'CustomNumberInput-button CustomNumberInput-decrementButton',
children: '▾',
},
incrementButton: {
className: 'CustomNumberInput-button CustomNumberInput-incrementButton',
children: '▴',
},
}}
aria-label="Demo number input"
placeholder="Type a number…"
Expand Down Expand Up @@ -86,7 +92,7 @@ function Styles() {
box-shadow: 0 0 0 3px ${isDarkMode ? cyan[500] : cyan[200]};
}
.CustomNumberInput .input {
.CustomNumberInput .CustomNumberInput-input {
font-family: inherit;
font-size: inherit;
font-weight: inherit;
Expand All @@ -102,11 +108,11 @@ function Styles() {
outline: 0;
}
.CustomNumberInput .input:focus-visible {
.CustomNumberInput .CustomNumberInput-input:focus-visible {
outline: 0;
}
.CustomNumberInput .btn {
.CustomNumberInput .CustomNumberInput-button {
display: flex;
flex-flow: row nowrap;
justify-content: center;
Expand All @@ -128,18 +134,18 @@ function Styles() {
transition-duration: 120ms;
}
.CustomNumberInput .btn:hover {
.CustomNumberInput .CustomNumberInput-button:hover {
background: ${isDarkMode ? grey[800] : grey[50]};
border-color: ${isDarkMode ? grey[600] : grey[300]};
cursor: pointer;
}
.CustomNumberInput .btn.increment {
.CustomNumberInput .CustomNumberInput-button.CustomNumberInput-incrementButton {
grid-column: 2/3;
grid-row: 1/2;
}
.CustomNumberInput .btn.decrement {
.CustomNumberInput .CustomNumberInput-button.CustomNumberInput-decrementButton {
grid-column: 2/3;
grid-row: 2/3;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,48 +1,99 @@
import * as React from 'react';
import { Unstable_NumberInput as NumberInput } from '@mui/base/Unstable_NumberInput';
import PropTypes from 'prop-types';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import clsx from 'clsx';

const CustomNumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
export default function NumberInputBasic() {
const [value, setValue] = React.useState();
return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}

const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn);

const NumberInput = React.forwardRef(function NumberInput(props, ref) {
return (
<BaseNumberInput
{...props}
ref={ref}
slotProps={{
root: (ownerState) => ({
className: clsx(
'grid grid-cols-[1fr_19px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 ',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
),
}),
input: {
className:
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
root: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.root,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'grid grid-cols-[1fr_19px] grid-rows-2 overflow-hidden font-sans rounded-lg text-slate-900 dark:text-slate-300 border border-solid bg-white dark:bg-slate-900 hover:border-violet-400 dark:hover:border-violet-400 focus-visible:outline-0 ',
ownerState.focused
? 'border-violet-400 dark:border-violet-400 shadow-lg shadow-outline-purple dark:shadow-outline-purple'
: 'border-slate-300 dark:border-slate-600 shadow-md shadow-slate-100 dark:shadow-slate-900',
resolvedSlotProps?.className,
),
};
},
incrementButton: {
children: '▴',
className:
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center appearance-none p-0 w-[19px] h-[19px] text-sm box-border leading-[1.2] border-0 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800 border-slate-300 dark:border-slate-600 col-start-2 col-end-3 row-start-1 row-end-2',
input: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.input,
ownerState,
);
return {
...resolvedSlotProps,
className: clsx(
'col-start-1 col-end-2 row-start-1 row-end-3 text-sm font-sans leading-normal text-slate-900 bg-inherit border-0 rounded-[inherit] dark:text-slate-300 px-3 py-2 outline-0 focus-visible:outline-0 focus-visible:outline-none',
resolvedSlotProps?.className,
),
};
},
decrementButton: {
children: '▾',
className:
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center appearance-none p-0 w-[19px] h-[19px] text-sm box-border leading-[1.2] border-0 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800 border-slate-300 dark:border-slate-600 col-start-2 col-end-3 row-start-2 row-end-3',
incrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.incrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▴',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center appearance-none p-0 w-[19px] h-[19px] text-sm box-border leading-[1.2] border-0 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800 border-slate-300 dark:border-slate-600 col-start-2 col-end-3 row-start-1 row-end-2',
resolvedSlotProps?.className,
),
};
},
decrementButton: (ownerState) => {
const resolvedSlotProps = resolveSlotProps(
props.slotProps?.decrementButton,
ownerState,
);
return {
...resolvedSlotProps,
children: '▾',
className: clsx(
'font-[system-ui] flex flex-row flex-nowrap justify-center items-center appearance-none p-0 w-[19px] h-[19px] text-sm box-border leading-[1.2] border-0 bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-300 transition-all duration-[120ms] hover:cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-800 border-slate-300 dark:border-slate-600 col-start-2 col-end-3 row-start-2 row-end-3',
resolvedSlotProps?.className,
),
};
},
}}
{...props}
ref={ref}
/>
);
});

export default function NumberInputBasic() {
const [value, setValue] = React.useState();
return (
<CustomNumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
);
}
NumberInput.propTypes = {
/**
* The props used for each slot inside the NumberInput.
* @default {}
*/
slotProps: PropTypes.shape({
decrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
incrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
};
Loading

0 comments on commit 2843305

Please sign in to comment.