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

Fix: NumberInput tailwind examples utilize darkmode #39477

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

export default function NumberInputBasic() {
const [value, setValue] = React.useState();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
<div className={isDarkMode ? 'dark' : ''}>
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ import {
NumberInputProps,
NumberInputOwnerState,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

export default function NumberInputBasic() {
const [value, setValue] = React.useState<number | undefined>();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
<div className={isDarkMode ? 'dark' : ''}>
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

export default function NumberInputIntroduction() {
const [value, setValue] = React.useState();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
<div className={isDarkMode ? 'dark' : ''}>
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ import {
NumberInputProps,
NumberInputOwnerState,
} from '@mui/base/Unstable_NumberInput';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

export default function NumberInputIntroduction() {
const [value, setValue] = React.useState<number | undefined>();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
<div className={isDarkMode ? 'dark' : ''}>
<NumberInput
aria-label="Demo number input"
placeholder="Type a number…"
value={value}
onChange={(event, val) => setValue(val)}
/>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,44 @@ import * as React from 'react';
import { Unstable_NumberInput as BaseNumberInput } from '@mui/base/Unstable_NumberInput';
import RemoveIcon from '@mui/icons-material/Remove';
import AddIcon from '@mui/icons-material/Add';
import { useTheme } from '@mui/system';

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

const NumberInput = React.forwardRef(function CustomNumberInput(props, ref) {
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<BaseNumberInput
slotProps={{
root: {
className:
'leading-snug font-sans text-slate-900 dark:text-slate-300 flex flex-row flex-nowrap justify-center items-center',
},
input: {
className:
'leading-snug font-sans text-sm text-inherit bg-white dark:bg-slate-900 border border-solid border-slate-300 dark:border-slate-600 rounded-[4px] my-0 mx-1 py-2.5 px-3 outline-0 min-w-0 w-16 text-center focus-visible:outline-0 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus-visible:outline-none',
},
incrementButton: {
children: <AddIcon />,
className:
'order-1 text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800',
},
decrementButton: {
children: <RemoveIcon />,
className:
'text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800',
},
}}
{...props}
ref={ref}
/>
<div className={isDarkMode ? 'dark' : ''}>
<BaseNumberInput
slotProps={{
root: {
className:
'leading-snug font-sans text-slate-900 dark:text-slate-300 flex flex-row flex-nowrap justify-center items-center',
},
input: {
className:
'leading-snug font-sans text-sm text-inherit bg-white dark:bg-slate-900 border border-solid border-slate-300 dark:border-slate-600 rounded-[4px] my-0 mx-1 py-2.5 px-3 outline-0 min-w-0 w-16 text-center focus-visible:outline-0 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus-visible:outline-none',
},
incrementButton: {
children: <AddIcon />,
className:
'order-1 text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800 dark:text-purple-400',
},
decrementButton: {
children: <RemoveIcon />,
className:
'text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800 dark:text-purple-400',
},
}}
{...props}
ref={ref}
/>
</div>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,47 @@ import {
} from '@mui/base/Unstable_NumberInput';
import RemoveIcon from '@mui/icons-material/Remove';
import AddIcon from '@mui/icons-material/Add';
import { useTheme } from '@mui/system';

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

const NumberInput = React.forwardRef(function CustomNumberInput(
props: NumberInputProps,
ref: React.ForwardedRef<HTMLDivElement>,
) {
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<BaseNumberInput
slotProps={{
root: {
className:
'leading-snug font-sans text-slate-900 dark:text-slate-300 flex flex-row flex-nowrap justify-center items-center',
},
input: {
className:
'leading-snug font-sans text-sm text-inherit bg-white dark:bg-slate-900 border border-solid border-slate-300 dark:border-slate-600 rounded-[4px] my-0 mx-1 py-2.5 px-3 outline-0 min-w-0 w-16 text-center focus-visible:outline-0 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus-visible:outline-none',
},
incrementButton: {
children: <AddIcon />,
className:
'order-1 text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800',
},
decrementButton: {
children: <RemoveIcon />,
className:
'text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800',
},
}}
{...props}
ref={ref}
/>
<div className={isDarkMode ? 'dark' : ''}>
<BaseNumberInput
slotProps={{
root: {
className:
'leading-snug font-sans text-slate-900 dark:text-slate-300 flex flex-row flex-nowrap justify-center items-center',
},
input: {
className:
'leading-snug font-sans text-sm text-inherit bg-white dark:bg-slate-900 border border-solid border-slate-300 dark:border-slate-600 rounded-[4px] my-0 mx-1 py-2.5 px-3 outline-0 min-w-0 w-16 text-center focus-visible:outline-0 hover:border-purple-500 dark:hover:border-purple-500 focus:border-purple-500 dark:focus:border-purple-500 focus:shadow-outline-purple dark:focus:shadow-outline-purple focus-visible:outline-none',
},
incrementButton: {
children: <AddIcon />,
className:
'order-1 text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800 dark:text-purple-400',
},
decrementButton: {
children: <RemoveIcon />,
className:
'text-sm font-sans box-border leading-normal border-0 rounded-full bg-transparent w-10 h-10 flex flex-row flex-nowrap justify-center items-center transition-all duration-[120ms] focus-visible:outline-0 hover:cursor-pointer hover:bg-purple-100 dark:hover:bg-purple-800 dark:text-purple-400',
},
}}
{...props}
ref={ref}
/>
</div>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

const CompactNumberInput = React.forwardRef(function CompactNumberInput(props, ref) {
const { className, ...rest } = props;
const {
Expand Down Expand Up @@ -72,9 +78,15 @@ CompactNumberInput.propTypes = {

export default function UseNumberInputCompact() {
const [value, setValue] = React.useState();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<div className="flex flex-row flex-nowrap items-center gap-x-8">
<div
className={`${
isDarkMode ? 'dark' : ''
} flex flex-row flex-nowrap items-center gap-x-8`}
>
<CompactNumberInput
aria-label="Compact number input"
placeholder="Type a number…"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import {
UseNumberInputParameters,
} from '@mui/base/unstable_useNumberInput';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { useTheme } from '@mui/system';
import clsx from 'clsx';

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

const CompactNumberInput = React.forwardRef(function CompactNumberInput(
props: Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> &
UseNumberInputParameters,
Expand Down Expand Up @@ -74,9 +80,15 @@ const CompactNumberInput = React.forwardRef(function CompactNumberInput(

export default function UseNumberInputCompact() {
const [value, setValue] = React.useState<number | undefined>();
// Replace this with your app logic for determining dark modes
const isDarkMode = useIsDarkMode();

return (
<div className="flex flex-row flex-nowrap items-center gap-x-8">
<div
className={`${
isDarkMode ? 'dark' : ''
} flex flex-row flex-nowrap items-center gap-x-8`}
>
<CompactNumberInput
aria-label="Compact number input"
placeholder="Type a number…"
Expand Down
Loading