Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Dec 29, 2021
1 parent 81b6b71 commit 72a19c4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
26 changes: 21 additions & 5 deletions packages/mui-base/src/MultiSelectUnstyled/MultiSelectUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
import MultiSelectUnstyledProps, {
MultiSelectUnstyledOwnerState,
} from './MultiSelectUnstyledProps';
import {
flattenOptionGroups,
getOptionsFromChildren,
useUtilityClasses,
} from '../SelectUnstyled/utils';
import { flattenOptionGroups, getOptionsFromChildren } from '../SelectUnstyled/utils';
import useSelect from '../SelectUnstyled/useSelect';
import { SelectChild, SelectOption } from '../SelectUnstyled/useSelectProps';
import { appendOwnerState } from '../utils';
Expand All @@ -21,11 +17,31 @@ import {
SelectUnstyledContext,
SelectUnstyledContextType,
} from '../SelectUnstyled/SelectUnstyledContext';
import composeClasses from '../composeClasses';
import { getSelectUnstyledUtilityClass } from '../SelectUnstyled/selectUnstyledClasses';

function defaultRenderMultipleValues<TValue>(selectedOptions: SelectOption<TValue>[]) {
return <React.Fragment>{selectedOptions.map((o) => o.label).join(', ')}</React.Fragment>;
}

function useUtilityClasses(ownerState: MultiSelectUnstyledOwnerState<any>) {
const { active, disabled, open, focusVisible } = ownerState;

const slots = {
button: [
'button',
disabled && 'disabled',
focusVisible && 'focusVisible',
active && 'active',
open && 'expanded',
],
listbox: ['listbox', disabled && 'disabled'],
option: ['option'],
};

return composeClasses(slots, getSelectUnstyledUtilityClass, {});
}

/**
* The foundation for building custom-styled multi-selection select components.
*/
Expand Down
22 changes: 21 additions & 1 deletion packages/mui-base/src/SelectUnstyled/SelectUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@ import {
unstable_useControlled as useControlled,
} from '@mui/utils';
import { SelectUnstyledOwnerState, SelectUnstyledProps } from './SelectUnstyledProps';
import { flattenOptionGroups, getOptionsFromChildren, useUtilityClasses } from './utils';
import { flattenOptionGroups, getOptionsFromChildren } from './utils';
import useSelect from './useSelect';
import { SelectChild, SelectOption } from './useSelectProps';
import { appendOwnerState } from '../utils';
import PopperUnstyled from '../PopperUnstyled';
import { SelectUnstyledContext, SelectUnstyledContextType } from './SelectUnstyledContext';
import composeClasses from '../composeClasses';
import { getSelectUnstyledUtilityClass } from './selectUnstyledClasses';

function defaultRenderSingleValue<TValue>(selectedOption: SelectOption<TValue> | null) {
return selectedOption?.label ?? '';
}

function useUtilityClasses(ownerState: SelectUnstyledOwnerState<any>) {
const { active, disabled, open, focusVisible } = ownerState;

const slots = {
button: [
'button',
disabled && 'disabled',
focusVisible && 'focusVisible',
active && 'active',
open && 'expanded',
],
listbox: ['listbox', disabled && 'disabled'],
option: ['option'],
};

return composeClasses(slots, getSelectUnstyledUtilityClass, {});
}

/**
* The foundation for building custom-styled select components.
*/
Expand Down
24 changes: 0 additions & 24 deletions packages/mui-base/src/SelectUnstyled/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';
import composeClasses from '../composeClasses';
import { OptionUnstyledProps } from '../OptionUnstyled';
import { OptionGroupUnstyledProps } from '../OptionGroupUnstyled';
import { getSelectUnstyledUtilityClass } from './selectUnstyledClasses';
import { SelectUnstyledOwnerState } from './SelectUnstyledProps';
import { MultiSelectUnstyledOwnerState } from '../MultiSelectUnstyled/MultiSelectUnstyledProps';
import { isOptionGroup, SelectChild, SelectOption, SelectOptionGroup } from './useSelectProps';

export function areOptionsEqual<TValue>(
Expand Down Expand Up @@ -57,26 +53,6 @@ export function getOptionsFromChildren<TValue>(children: React.ReactNode): Selec
return selectChildren ?? [];
}

export function useUtilityClasses(
ownerState: SelectUnstyledOwnerState<any> | MultiSelectUnstyledOwnerState<any>,
) {
const { active, disabled, open, focusVisible } = ownerState;

const slots = {
button: [
'button',
disabled && 'disabled',
focusVisible && 'focusVisible',
active && 'active',
open && 'expanded',
],
listbox: ['listbox', disabled && 'disabled'],
option: ['option'],
};

return composeClasses(slots, getSelectUnstyledUtilityClass, {});
}

export function flattenOptionGroups<TValue>(
groupedOptions: SelectChild<TValue>[],
isGroupDisabled: boolean = false,
Expand Down

0 comments on commit 72a19c4

Please sign in to comment.