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

[pickers] POC: PickersTextField styling - outlined variant #10778

Merged
merged 28 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ec13e1a
wip
noraleonte Oct 13, 2023
0201c2d
Merge branch 'master' of https://github.com/noraleonte/mui-x into fak…
noraleonte Oct 17, 2023
349ed30
outlined input wip
noraleonte Oct 18, 2023
23c017a
WIP 1
noraleonte Oct 23, 2023
a3d6637
fix conflicts
noraleonte Oct 24, 2023
e82202e
adjustments
noraleonte Oct 24, 2023
a8b624e
fix todos
noraleonte Oct 24, 2023
1052aca
scripts
noraleonte Oct 24, 2023
1e938c7
adornments wip
noraleonte Oct 30, 2023
f3a63a2
Iteration 1 outlined FakeTextField
noraleonte Nov 2, 2023
55164af
Merge branch 'master' of https://github.com/noraleonte/mui-x into fak…
noraleonte Nov 2, 2023
e4047b2
scripts
noraleonte Nov 2, 2023
1b130ca
Merge branch 'master' of https://github.com/noraleonte/mui-x into fak…
noraleonte Nov 6, 2023
babb6e7
adjustments
noraleonte Nov 9, 2023
c425072
update fakeInput
noraleonte Nov 17, 2023
595007d
Merge branch 'next' of https://github.com/noraleonte/mui-x into fake-…
noraleonte Nov 20, 2023
25f711c
wip
noraleonte Nov 22, 2023
68fe9f1
Apply suggestions from code review - Flavien
noraleonte Nov 22, 2023
66db521
wip
noraleonte Nov 22, 2023
9763632
Merge branch 'fake-textfield-styling' of https://github.com/noraleont…
noraleonte Nov 22, 2023
5881456
remove demo
noraleonte Nov 22, 2023
2aa1414
make ts happy
noraleonte Nov 22, 2023
9a76cd0
ts
noraleonte Nov 22, 2023
fb1acd7
ts
noraleonte Nov 22, 2023
3969f89
fix
noraleonte Nov 22, 2023
7a21081
Cleanup
noraleonte Nov 24, 2023
15bed58
Apply styles to separators
noraleonte Nov 24, 2023
05b6540
rename fake TextField
noraleonte Nov 24, 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
135 changes: 135 additions & 0 deletions docs/data/date-pickers/date-field/FakeTextFieldWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { useLocaleText, useUtils } from '@mui/x-date-pickers/internals';
import { TextField, Box } from '@mui/material';
import InputAdornment from '@mui/material/InputAdornment';
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { FakeTextField } from '@mui/x-date-pickers/internals/components/FakeTextField';
import {
addPositionPropertiesToSections,
splitFormatIntoSections,
} from '@mui/x-date-pickers/internals/hooks/useField';

const date = dayjs('2022-04-17');
const timezone = 'default';
const format = 'MM-DD-YYYY';
const formatDensity = 'spacious';
const shouldRespectLeadingZeros = false;
const isRTL = false;

function AppContent() {
const utils = useUtils();
const localeText = useLocaleText();
const ref = React.useRef(null);

const sections = React.useMemo(
() =>
addPositionPropertiesToSections(
splitFormatIntoSections(
utils,
timezone,
localeText,
format,
date,
formatDensity,
shouldRespectLeadingZeros,
isRTL,
),
isRTL,
),
[utils, localeText],
);

// simulating behavior; TODO: Delete
const elements = React.useMemo(
() =>
sections.map((section, sectionIndex) => ({
container: {
'data-sectionindex': sectionIndex,
onClick: () => {},
},
content: {
className: 'content',
role: 'textbox',
children: section.value || section.placeholder,
inputMode: section.contentType === 'letter' ? 'text' : 'numeric',
suppressContentEditableWarning: true,
style: {
outline: 'none',
},
},
before: {
className: 'before',
children: section.startSeparator,
style: { whiteSpace: 'pre' },
},
after: {
className: 'after',
children: section.endSeparator,
style: { whiteSpace: 'pre' },
},
})),
[sections],
);

return (
<FakeTextField
label="test"
required
helperText="test"
elements={elements}
size="small"
error
// disabled
color="secondary"
fullWidth
onChange={() => {}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<CalendarMonthIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<CalendarMonthIcon />
</InputAdornment>
),
}}
{...{ ref }}
/>
);
}

export default function FakeTextFieldWrapper() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<Box>
<AppContent />
<TextField
required
error
label="test"
// value="04-17-2022"
size="small"
helperText="test"
fullWidth
InputProps={{
startAdornment: (
<InputAdornment position="start">
<CalendarMonthIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<CalendarMonthIcon />
</InputAdornment>
),
}}
/>
</Box>
</LocalizationProvider>
);
}
136 changes: 136 additions & 0 deletions docs/data/date-pickers/date-field/FakeTextFieldWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import * as React from 'react';
import dayjs from 'dayjs';
import { useLocaleText, useUtils } from '@mui/x-date-pickers/internals';
import { TextField, Box } from '@mui/material';
import InputAdornment from '@mui/material/InputAdornment';
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { FakeTextField } from '@mui/x-date-pickers/internals/components/FakeTextField';
import {
addPositionPropertiesToSections,
splitFormatIntoSections,
} from '@mui/x-date-pickers/internals/hooks/useField';

const date = dayjs('2022-04-17');
const timezone = 'default';
const format = 'MM-DD-YYYY';
const formatDensity = 'spacious';
const shouldRespectLeadingZeros = false;
const isRTL = false;

function AppContent() {
const utils = useUtils();
const localeText = useLocaleText();
const ref = React.useRef(null);

const sections = React.useMemo(
() =>
addPositionPropertiesToSections(
splitFormatIntoSections(
utils,
timezone,
localeText,
format,
date,
formatDensity,
shouldRespectLeadingZeros,
isRTL,
),
isRTL,
),
[utils, localeText],
);

// simulating behavior; TODO: Delete
const elements = React.useMemo(
() =>
sections.map((section, sectionIndex) => ({
container: {
'data-sectionindex': sectionIndex,
onClick: () => {},
} as React.HTMLAttributes<HTMLSpanElement>,
content: {
className: 'content',
role: 'textbox',
children: section.value || section.placeholder,
inputMode: section.contentType === 'letter' ? 'text' : 'numeric',
suppressContentEditableWarning: true,
style: {
outline: 'none',
},
},
before: {
className: 'before',
children: section.startSeparator,
style: { whiteSpace: 'pre' },
},
after: {
className: 'after',
children: section.endSeparator,
style: { whiteSpace: 'pre' },
},
})),
[sections],
);

return (
<FakeTextField
label="test"
required
helperText="test"
elements={elements}
size="small"
error
// disabled
color="secondary"
fullWidth
onChange={() => {}}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<CalendarMonthIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<CalendarMonthIcon />
</InputAdornment>
),
}}
{...{ ref }}
/>
);
}

export default function FakeTextFieldWrapper() {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<Box>
<AppContent />

<TextField
required
error
label="test"
// value="04-17-2022"
size="small"
helperText="test"
fullWidth
InputProps={{
startAdornment: (
<InputAdornment position="start">
<CalendarMonthIcon />
</InputAdornment>
),
endAdornment: (
<InputAdornment position="end">
<CalendarMonthIcon />
</InputAdornment>
),
}}
/>
</Box>
</LocalizationProvider>
);
}
6 changes: 6 additions & 0 deletions docs/data/date-pickers/date-field/date-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ packageName: '@mui/x-date-pickers'

{{"demo": "BasicDateField.js"}}

## FakeTextField

putting this demo here for easy testing, will remove before merging

{{"demo": "FakeTextFieldWrapper.js"}}

## Uncontrolled vs. controlled value

The value of the component can be uncontrolled or controlled.
Expand Down
Loading