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

[docs][base] Move styles to the bottom of demos code for SelectUnstyled #36718

Merged
merged 2 commits into from
Apr 28, 2023
Merged
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
78 changes: 39 additions & 39 deletions docs/data/base/components/select/UnstyledSelectControlled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ import Option, { optionClasses } from '@mui/base/Option';
import Popper from '@mui/base/Popper';
import { styled } from '@mui/system';

export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>

<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}

function CustomSelect(props) {
const slots = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

CustomSelect.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};

const blue = {
100: '#DAECFF',
200: '#99CCF3',
Expand Down Expand Up @@ -136,42 +175,3 @@ const Paragraph = styled('p')(
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);

function CustomSelect(props) {
const slots = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

CustomSelect.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};

export default function UnstyledSelectsMultiple() {
const [value, setValue] = React.useState(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>

<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}
52 changes: 26 additions & 26 deletions docs/data/base/components/select/UnstyledSelectControlled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ import Option, { optionClasses } from '@mui/base/Option';
import Popper from '@mui/base/Popper';
import { styled } from '@mui/system';

export default function UnstyledSelectControlled() {
const [value, setValue] = React.useState<number | null>(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>

<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}

function CustomSelect(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

const blue = {
100: '#DAECFF',
200: '#99CCF3',
Expand Down Expand Up @@ -135,29 +161,3 @@ const Paragraph = styled('p')(
color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]};
`,
);

function CustomSelect(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

export default function UnstyledSelectsMultiple() {
const [value, setValue] = React.useState<number | null>(10);
return (
<div>
<CustomSelect value={value} onChange={(e, newValue) => setValue(newValue)}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>

<Paragraph>Selected value: {value}</Paragraph>
</div>
);
}
92 changes: 46 additions & 46 deletions docs/data/base/components/select/UnstyledSelectCustomRenderValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,52 @@ import Option, { optionClasses } from '@mui/base/Option';
import Popper from '@mui/base/Popper';
import { styled } from '@mui/system';

export default function UnstyledSelectCustomRenderValue() {
return (
<CustomSelect renderValue={renderValue}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>
);
}

function CustomSelect(props) {
const slots = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

CustomSelect.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};

function renderValue(option) {
if (option == null) {
return <span>Select an option...</span>;
}

return (
<span>
{option.label} ({option.value})
</span>
);
}

const blue = {
100: '#DAECFF',
200: '#99CCF3',
Expand Down Expand Up @@ -127,49 +173,3 @@ const StyledOption = styled(Option)(
const StyledPopper = styled(Popper)`
z-index: 1;
`;

function CustomSelect(props) {
const slots = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

CustomSelect.propTypes = {
/**
* The components used for each slot inside the Select.
* Either a string to use a HTML element or a component.
* @default {}
*/
slots: PropTypes.shape({
listbox: PropTypes.elementType,
popper: PropTypes.func,
root: PropTypes.elementType,
}),
};

function renderValue(option) {
if (option == null) {
return <span>Select an option...</span>;
}

return (
<span>
{option.label} ({option.value})
</span>
);
}

export default function UnstyledSelectCustomRenderValue() {
return (
<CustomSelect renderValue={renderValue}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,39 @@ import Option, { optionClasses } from '@mui/base/Option';
import Popper from '@mui/base/Popper';
import { styled } from '@mui/system';

export default function UnstyledSelectCustomRenderValue() {
return (
<CustomSelect renderValue={renderValue}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>
);
}

function CustomSelect(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

function renderValue(option: SelectOption<number> | null) {
if (option == null) {
return <span>Select an option...</span>;
}

return (
<span>
{option.label} ({option.value})
</span>
);
}

const blue = {
100: '#DAECFF',
200: '#99CCF3',
Expand Down Expand Up @@ -126,36 +159,3 @@ const StyledOption = styled(Option)(
const StyledPopper = styled(Popper)`
z-index: 1;
`;

function CustomSelect(props: SelectProps<number, false>) {
const slots: SelectProps<number, false>['slots'] = {
root: StyledButton,
listbox: StyledListbox,
popper: StyledPopper,
...props.slots,
};

return <Select {...props} slots={slots} />;
}

function renderValue(option: SelectOption<number> | null) {
if (option == null) {
return <span>Select an option...</span>;
}

return (
<span>
{option.label} ({option.value})
</span>
);
}

export default function UnstyledSelectCustomRenderValue() {
return (
<CustomSelect renderValue={renderValue}>
<StyledOption value={10}>Ten</StyledOption>
<StyledOption value={20}>Twenty</StyledOption>
<StyledOption value={30}>Thirty</StyledOption>
</CustomSelect>
);
}
Loading