Skip to content

Commit

Permalink
move default definition
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Feb 6, 2024
1 parent 59f1c27 commit f5f1a19
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
9 changes: 5 additions & 4 deletions docs/src/modules/components/ApiPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ClassesSection, {
getClassesToC,
} from 'docs/src/modules/components/ApiPage/sections/ClassesSection';
import SlotsSection from 'docs/src/modules/components/ApiPage/sections/SlotsSection';
import { DEFAULT_API_LAYOUT_STORAGE_KEYS } from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';

export function getTranslatedHeader(t, header) {
const translations = {
Expand Down Expand Up @@ -73,7 +74,7 @@ export default function ApiPage(props) {
disableAd = false,
pageContent,
defaultLayout = 'table',
layoutStorageKey,
layoutStorageKey = DEFAULT_API_LAYOUT_STORAGE_KEYS,
} = props;
const t = useTranslate();
const userLanguage = useUserLanguage();
Expand Down Expand Up @@ -264,7 +265,7 @@ export default function ApiPage(props) {
componentName={pageContent.name}
spreadHint={spreadHint}
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.props}
layoutStorageKey={layoutStorageKey.props}
/>
{cssComponent && (
<React.Fragment>
Expand Down Expand Up @@ -323,7 +324,7 @@ export default function ApiPage(props) {
t('api-docs.slotDescription').replace(/{{slotGuideLink}}/, slotGuideLink)
}
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.slots}
layoutStorageKey={layoutStorageKey.slots}
/>
<ClassesSection
componentClasses={componentClasses}
Expand All @@ -332,7 +333,7 @@ export default function ApiPage(props) {
spreadHint={t('api-docs.classesDescription')}
styleOverridesLink={styleOverridesLink}
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.classes}
layoutStorageKey={layoutStorageKey.classes}
displayClassKeys
/>
</MarkdownElement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useTranslate } from 'docs/src/modules/utils/i18n';
import { ComponentClassDefinition } from '@mui-internal/docs-utilities';
import Box from '@mui/material/Box';
import ToggleDisplayOption, {
API_LAYOUT_STORAGE_KEYS,
ApiDisplayOptions,
useApiPageOption,
} from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';
Expand Down Expand Up @@ -51,7 +50,7 @@ export type ClassesSectionProps = {
titleHash: string;
level?: 'h2' | 'h3' | 'h4';
defaultLayout: ApiDisplayOptions;
layoutStorageKey?: string;
layoutStorageKey: string;
displayClassKeys: boolean;
styleOverridesLink: string;
};
Expand All @@ -68,7 +67,7 @@ export default function ClassesSection(props: ClassesSectionProps) {
displayClassKeys,
styleOverridesLink,
defaultLayout,
layoutStorageKey = API_LAYOUT_STORAGE_KEYS.classes,
layoutStorageKey,
} = props;
const t = useTranslate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PropTypes from 'prop-types';
import Box from '@mui/material/Box';
import { useTranslate } from 'docs/src/modules/utils/i18n';
import ToggleDisplayOption, {
API_LAYOUT_STORAGE_KEYS,
useApiPageOption,
} from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';
import PropertiesList, { getHash } from 'docs/src/modules/components/ApiPage/list/PropertiesList';
Expand Down Expand Up @@ -52,7 +51,7 @@ export default function PropertiesSection(props) {
hooksParameters = false,
hooksReturnValue = false,
defaultLayout,
layoutStorageKey = API_LAYOUT_STORAGE_KEYS.props,
layoutStorageKey,
} = props;
const t = useTranslate();

Expand Down Expand Up @@ -154,7 +153,7 @@ PropertiesSection.propTypes = {
defaultLayout: PropTypes.oneOf(['collapsed', 'expanded', 'table']).isRequired,
hooksParameters: PropTypes.bool,
hooksReturnValue: PropTypes.bool,
layoutStorageKey: PropTypes.string,
layoutStorageKey: PropTypes.string.isRequired,
level: PropTypes.string,
properties: PropTypes.object.isRequired,
propertiesDescriptions: PropTypes.object.isRequired,
Expand Down
5 changes: 2 additions & 3 deletions docs/src/modules/components/ApiPage/sections/SlotsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react';
import Box from '@mui/material/Box';
import { useTranslate } from 'docs/src/modules/utils/i18n';
import ToggleDisplayOption, {
API_LAYOUT_STORAGE_KEYS,
ApiDisplayOptions,
useApiPageOption,
} from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';
Expand All @@ -18,7 +17,7 @@ export type SlotsSectionProps = {
titleHash?: string;
level?: 'h2' | 'h3' | 'h4';
defaultLayout: ApiDisplayOptions;
layoutStorageKey?: string;
layoutStorageKey: string;
spreadHint?: string;
};

Expand All @@ -32,7 +31,7 @@ export default function SlotsSection(props: SlotsSectionProps) {
level: Level = 'h2',
spreadHint,
defaultLayout,
layoutStorageKey = API_LAYOUT_STORAGE_KEYS.slots,
layoutStorageKey,
} = props;
const t = useTranslate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ApiDisplayOptions = 'collapsed' | 'expanded' | 'table';

const options: ApiDisplayOptions[] = ['collapsed', 'expanded', 'table'];

export const API_LAYOUT_STORAGE_KEYS = {
export const DEFAULT_API_LAYOUT_STORAGE_KEYS = {
slots: 'apiPage_slots',
props: 'apiPage_props',
classes: 'apiPage_classes',
Expand Down Expand Up @@ -71,20 +71,6 @@ export function useApiPageOption(
return [option, updateOption];
}

export function getApiPageLayout() {
const rep: { [key: string]: string } = {};

Object.values(API_LAYOUT_STORAGE_KEYS).forEach((localStorageKey) => {
try {
const savedOption = localStorage.getItem(localStorageKey);
rep[localStorageKey] = savedOption || 'none';
} catch {
rep[localStorageKey] = 'none';
}
});
return rep;
}

// Fix Toggle buton highlight (taken from /~https://github.com/mui/material-ui/issues/18091)
type TooltipToggleButtonProps = ToggleButtonProps & {
/**
Expand Down
14 changes: 10 additions & 4 deletions docs/src/modules/components/ComponentsApiContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import PropertiesSection from 'docs/src/modules/components/ApiPage/sections/PropertiesSection';
import ClassesSection from 'docs/src/modules/components/ApiPage/sections/ClassesSection';
import SlotsSection from 'docs/src/modules/components/ApiPage/sections/SlotsSection';
import { DEFAULT_API_LAYOUT_STORAGE_KEYS } from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';

function getTranslatedHeader(t, header, text) {
const translations = {
Expand Down Expand Up @@ -49,7 +50,12 @@ Heading.propTypes = {
};

export default function ComponentsApiContent(props) {
const { descriptions, pageContents, defaultLayout = 'table', layoutStorageKey } = props;
const {
descriptions,
pageContents,
defaultLayout = 'table',
layoutStorageKey = DEFAULT_API_LAYOUT_STORAGE_KEYS,
} = props;
const t = useTranslate();
const userLanguage = useUserLanguage();
const router = useRouter();
Expand Down Expand Up @@ -151,7 +157,7 @@ export default function ComponentsApiContent(props) {
level="h3"
titleHash={`${componentNameKebabCase}-props`}
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.props}
layoutStorageKey={layoutStorageKey.props}
/>
<br />
{cssComponent && (
Expand Down Expand Up @@ -219,7 +225,7 @@ export default function ComponentsApiContent(props) {
t('api-docs.slotDescription').replace(/{{slotGuideLink}}/, slotGuideLink)
}
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.slots}
layoutStorageKey={layoutStorageKey.slots}
/>
<ClassesSection
componentClasses={componentClasses}
Expand All @@ -229,7 +235,7 @@ export default function ComponentsApiContent(props) {
titleHash={`${componentNameKebabCase}-classes`}
level="h3"
defaultLayout={defaultLayout}
layoutStorageKey={layoutStorageKey?.classes}
layoutStorageKey={layoutStorageKey.classes}
/>
</MarkdownElement>
<svg style={{ display: 'none' }} xmlns="http://www.w3.org/2000/svg">
Expand Down
8 changes: 7 additions & 1 deletion docs/src/modules/components/HooksApiContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n';
import PropertiesSection from 'docs/src/modules/components/ApiPage/sections/PropertiesSection';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import { DEFAULT_API_LAYOUT_STORAGE_KEYS } from 'docs/src/modules/components/ApiPage/sections/ToggleDisplayOption';

function getTranslatedHeader(t, header, text) {
const translations = {
Expand Down Expand Up @@ -43,7 +44,12 @@ Heading.propTypes = {
};

export default function HooksApiContent(props) {
const { descriptions, pagesContents, defaultLayout = 'table', layoutStorageKey } = props;
const {
descriptions,
pagesContents,
defaultLayout = 'table',
layoutStorageKey = DEFAULT_API_LAYOUT_STORAGE_KEYS,
} = props;
const userLanguage = useUserLanguage();
const t = useTranslate();

Expand Down

0 comments on commit f5f1a19

Please sign in to comment.