Skip to content

Commit

Permalink
Update proptypes and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Nov 20, 2024
1 parent 85ae13e commit a2a0bfe
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docs/data/api/tabs-root.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"props": {
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"defaultValue": { "type": { "name": "any" } },
"defaultValue": { "type": { "name": "any" }, "default": "0" },
"direction": {
"type": { "name": "enum", "description": "'ltr'<br>&#124;&nbsp;'rtl'" },
"default": "'ltr'"
Expand Down
2 changes: 1 addition & 1 deletion docs/data/translations/api-docs/tab/tab.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"render": { "description": "A function to customize rendering of the component." },
"value": {
"description": "You can provide your own value. Otherwise, it falls back to the child position index."
"description": "The value of the Tab. When not specified, the value is the child position index."
}
},
"classDescriptions": {}
Expand Down
4 changes: 2 additions & 2 deletions docs/data/translations/api-docs/tabs-root/tabs-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"description": "Class names applied to the element or a function that returns them based on the component&#39;s state."
},
"defaultValue": {
"description": "The default value. Use when the component is not controlled."
"description": "The default value. Use when the component is not controlled. When the value is <code>null</code>, no Tab will be selected."
},
"direction": { "description": "The direction of the text." },
"onValueChange": { "description": "Callback invoked when new value is being set." },
"orientation": { "description": "The component orientation (layout flow direction)." },
"render": { "description": "A function to customize rendering of the component." },
"value": {
"description": "The value of the currently selected <code>Tab</code>. If you don&#39;t want any selected <code>Tab</code>, you can set this prop to <code>null</code>."
"description": "The value of the currently selected <code>Tab</code>. Use when the component is controlled. When the value is <code>null</code>, no Tab will be selected."
}
},
"classDescriptions": {}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/generated/tab.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"value": {
"type": "any",
"description": "You can provide your own value. Otherwise, it falls back to the child position index."
"description": "The value of the Tab.\nWhen not specified, the value is the child position index."
}
}
}
5 changes: 3 additions & 2 deletions docs/reference/generated/tabs-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"defaultValue": {
"type": "any",
"description": "The default value. Use when the component is not controlled."
"default": "0",
"description": "The default value. Use when the component is not controlled.\nWhen the value is `null`, no Tab will be selected."
},
"direction": {
"type": "'ltr' | 'rtl'",
Expand All @@ -30,7 +31,7 @@
},
"value": {
"type": "any",
"description": "The value of the currently selected `Tab`.\nIf you don't want any selected `Tab`, you can set this prop to `null`."
"description": "The value of the currently selected `Tab`. Use when the component is controlled.\nWhen the value is `null`, no Tab will be selected."
}
}
}
4 changes: 4 additions & 0 deletions packages/mui-base/src/Composite/List/CompositeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ CompositeList.propTypes /* remove-proptypes */ = {
labelsRef: PropTypes.shape({
current: PropTypes.arrayOf(PropTypes.string).isRequired,
}),
/**
* @ignore
*/
onMapChange: PropTypes.func,
} as any;

export { CompositeList };
8 changes: 8 additions & 0 deletions packages/mui-base/src/Composite/Root/CompositeRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ CompositeRoot.propTypes /* remove-proptypes */ = {
* @ignore
*/
onActiveIndexChange: PropTypes.func,
/**
* @ignore
*/
onMapChange: PropTypes.func,
/**
* @ignore
*/
Expand All @@ -141,6 +145,10 @@ CompositeRoot.propTypes /* remove-proptypes */ = {
* A function to customize rendering of the component.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* @ignore
*/
stopEventPropagation: PropTypes.bool,
} as any;

export { CompositeRoot };
60 changes: 54 additions & 6 deletions packages/mui-base/src/Tabs/Root/TabsRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import type { BaseUIComponentProps } from '../../utils/types';
import { CompositeList } from '../../Composite/List/CompositeList';
Expand Down Expand Up @@ -102,11 +103,56 @@ const TabsRoot = React.forwardRef(function TabsRoot(
);
});

TabsRoot.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* Class names applied to the element or a function that returns them based on the component's state.
*/
className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
/**
* The default value. Use when the component is not controlled.
* When the value is `null`, no Tab will be selected.
* @default 0
*/
defaultValue: PropTypes.any,
/**
* The direction of the text.
* @default 'ltr'
*/
direction: PropTypes.oneOf(['ltr', 'rtl']),
/**
* Callback invoked when new value is being set.
*/
onValueChange: PropTypes.func,
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
orientation: PropTypes.oneOf(['horizontal', 'vertical']),
/**
* A function to customize rendering of the component.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
/**
* The value of the currently selected `Tab`. Use when the component is controlled.
* When the value is `null`, no Tab will be selected.
*/
value: PropTypes.any,
} as any;

export { TabsRoot };

export type TabsOrientation = 'horizontal' | 'vertical';
export type TabsDirection = 'ltr' | 'rtl';
export type TabActivationDirection = 'left' | 'right' | 'up' | 'down' | 'none';
export type TabValue = any | null;

namespace TabsRoot {
export type OwnerState = {
Expand All @@ -115,16 +161,18 @@ namespace TabsRoot {
tabActivationDirection: TabActivationDirection;
};

export interface Props extends BaseUIComponentProps<'div', OwnerState> {
export interface Props extends Omit<BaseUIComponentProps<'div', OwnerState>, 'defaultValue'> {
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this prop to `null`.
* The value of the currently selected `Tab`. Use when the component is controlled.
* When the value is `null`, no Tab will be selected.
*/
value?: any | null;
value?: TabValue;
/**
* The default value. Use when the component is not controlled.
* When the value is `null`, no Tab will be selected.
* @default 0
*/
defaultValue?: any | null;
defaultValue?: TabValue;
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
Expand All @@ -138,6 +186,6 @@ namespace TabsRoot {
/**
* Callback invoked when new value is being set.
*/
onValueChange?: (value: any | null, event?: Event) => void;
onValueChange?: (value: TabValue, event?: Event) => void;
}
}
27 changes: 16 additions & 11 deletions packages/mui-base/src/Tabs/Root/TabsRootContext.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use client';
import * as React from 'react';
import { type TabMetadata } from '../Tab/useTab';
import { type TabActivationDirection } from './TabsRoot';
import type { TabActivationDirection, TabValue } from './TabsRoot';

export interface TabsRootContext {
/**
* The currently selected tab's value.
*/
value: any | null;
value: TabValue;
/**
* Callback for setting new value.
*/
onValueChange: (
value: any | null,
value: TabValue,
activationDirection: TabActivationDirection,
event: Event,
) => void;
Expand All @@ -25,18 +25,23 @@ export interface TabsRootContext {
*/
direction: 'ltr' | 'rtl';
/**
* Registers a function that returns the id of the tab with the given value.
* Gets the element of the Tab with the given value.
* @param {any | undefined} value Value to find the tab for.
*/
// registerGetTabIdByPanelValueOrIndexFn?: (lookupFunction: (id: any) => string | undefined) => void;
getTabElementBySelectedValue: (selectedValue: any | undefined) => HTMLElement | null;
getTabElementBySelectedValue: (selectedValue: TabValue | undefined) => HTMLElement | null;
/**
* Gets the id of the tab with the given value.
* @param {any | undefined} value Value to find the tab for.
* Gets the `id` attribute of the Tab that corresponds to the given TabPanel value or index.
* @param (any | undefined) panelValue Value to find the Tab for.
* @param (number) index The index of the TabPanel to look for.
*/
getTabIdByPanelValueOrIndex: (panelValue: any | undefined, index: number) => string | undefined;
getTabIdByPanelValueOrIndex: (
panelValue: TabValue | undefined,
index: number,
) => string | undefined;
/**
* Gets the id of the tab panel with the given value.
* @param {any | undefined} value Value to find the tab panel for.
* Gets the `id` attribute of the TabPanel that corresponds to the given Tab value or index.
* @param (any | undefined) tabValue Value to find the Tab for.
* @param (number) index The index of the Tab to look for.
*/
getTabPanelIdByTabValueOrIndex: (tabValue: any, index: number) => string | undefined;
setTabMap: (map: Map<Node, (TabMetadata & { index?: number | null }) | null>) => void;
Expand Down
Loading

0 comments on commit a2a0bfe

Please sign in to comment.