Skip to content

Commit

Permalink
Convert to namespace types
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Sep 5, 2024
1 parent 053b139 commit b595967
Show file tree
Hide file tree
Showing 29 changed files with 523 additions and 625 deletions.
6 changes: 0 additions & 6 deletions docs/data/api/slider-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
"default": "'ltr'"
},
"disabled": { "type": { "name": "bool" }, "default": "false" },
"id": { "type": { "name": "string" } },
"largeStep": { "type": { "name": "number" }, "default": "10" },
"max": { "type": { "name": "number" }, "default": "100" },
"min": { "type": { "name": "number" }, "default": "0" },
"minStepsBetweenValues": { "type": { "name": "number" }, "default": "0" },
"name": { "type": { "name": "string" } },
"onValueChange": {
"type": { "name": "func" },
"signature": {
Expand All @@ -35,8 +31,6 @@
"default": "'horizontal'"
},
"render": { "type": { "name": "union", "description": "element<br>&#124;&nbsp;func" } },
"step": { "type": { "name": "number" }, "default": "1" },
"tabIndex": { "type": { "name": "number" } },
"value": {
"type": { "name": "union", "description": "Array&lt;number&gt;<br>&#124;&nbsp;number" }
}
Expand Down
14 changes: 0 additions & 14 deletions docs/data/translations/api-docs/slider-root/slider-root.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@
"description": "Sets the direction. For right-to-left languages, the lowest value is on the right-hand side."
},
"disabled": { "description": "If <code>true</code>, the component is disabled." },
"id": { "description": "The id of the slider element." },
"largeStep": {
"description": "The granularity with which the slider can step through values when using Page Up/Page Down or Shift + Arrow Up/Arrow Down."
},
"max": {
"description": "The maximum allowed value of the slider. Should not be equal to min."
},
"min": {
"description": "The minimum allowed value of the slider. Should not be equal to max."
},
"minStepsBetweenValues": {
"description": "The minimum steps between values in a range slider."
},
"name": { "description": "Name attribute of the hidden <code>input</code> element." },
"onValueChange": {
"description": "Callback function that is fired when the slider&#39;s value changed.",
"typeDescriptions": {
Expand All @@ -45,12 +37,6 @@
},
"orientation": { "description": "The component orientation." },
"render": { "description": "A function to customize rendering of the component." },
"step": {
"description": "The granularity with which the slider can step through values. (A &quot;discrete&quot; slider.) The <code>min</code> prop serves as the origin for the valid values. We recommend (max - min) to be evenly divisible by the step."
},
"tabIndex": {
"description": "Tab index attribute of the Thumb component&#39;s <code>input</code> element."
},
"value": {
"description": "The value of the slider. For ranged sliders, provide an array with two values."
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/Slider/Control/SliderControl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import * as Slider from '@base_ui/react/Slider';
import { SliderProvider, type SliderProviderValue } from '@base_ui/react/Slider';
import { createRenderer, describeConformance } from '#test-utils';
import { SliderProvider } from '../Root/SliderProvider';

const NOOP = () => {};

describe('<Slider.Control />', () => {
const { render } = createRenderer();

const testProviderValue: SliderProviderValue = {
const testProviderValue: SliderProvider.Value = {
active: -1,
areValuesEqual: () => true,
axis: 'horizontal',
Expand Down
10 changes: 7 additions & 3 deletions packages/mui-base/src/Slider/Control/SliderControl.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import type { BaseUIComponentProps } from '../../utils/types';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import { useSliderContext } from '../Root/SliderProvider';
import { sliderStyleHookMapping } from '../Root/styleHooks';
import { SliderControlProps } from './SliderControl.types';
import type { SliderRoot } from '../Root/SliderRoot';
import { useSliderControl } from './useSliderControl';

/**
*
* Demos:
Expand All @@ -18,7 +18,7 @@ import { useSliderControl } from './useSliderControl';
* - [SliderControl API](https://base-ui.netlify.app/components/react-slider/#api-reference-SliderControl)
*/
const SliderControl = React.forwardRef(function SliderControl(
props: SliderControlProps,
props: SliderControl.Props,
forwardedRef: React.ForwardedRef<HTMLDivElement>,
) {
const { render: renderProp, className, ...otherProps } = props;
Expand Down Expand Up @@ -90,4 +90,8 @@ SliderControl.propTypes /* remove-proptypes */ = {
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export namespace SliderControl {
export interface Props extends BaseUIComponentProps<'span', SliderRoot.OwnerState> {}
}

export { SliderControl };
34 changes: 0 additions & 34 deletions packages/mui-base/src/Slider/Control/SliderControl.types.ts

This file was deleted.

43 changes: 39 additions & 4 deletions packages/mui-base/src/Slider/Control/useSliderControl.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import * as React from 'react';
import { mergeReactProps } from '../../utils/mergeReactProps';
import { ownerDocument } from '../../utils/owner';
import type { GenericHTMLProps } from '../../utils/types';
import { useForkRef } from '../../utils/useForkRef';
import { useEventCallback } from '../../utils/useEventCallback';
import { focusThumb, trackFinger, validateMinimumDistance } from '../Root/useSliderRoot';
import { UseSliderControlParameters, UseSliderControlReturnValue } from './SliderControl.types';
import {
focusThumb,
trackFinger,
type useSliderRoot,
validateMinimumDistance,
} from '../Root/useSliderRoot';
import { useFieldControlValidation } from '../../Field/Control/useFieldControlValidation';

const INTENTIONAL_DRAG_COUNT_THRESHOLD = 2;

export function useSliderControl(
parameters: UseSliderControlParameters,
): UseSliderControlReturnValue {
parameters: useSliderControl.Parameters,
): useSliderControl.ReturnValue {
const {
areValuesEqual,
disabled,
Expand Down Expand Up @@ -282,3 +287,33 @@ export function useSliderControl(
[getRootProps],
);
}

export namespace useSliderControl {
export interface Parameters
extends Pick<
useSliderRoot.ReturnValue,
| 'areValuesEqual'
| 'disabled'
| 'dragging'
| 'getFingerNewValue'
| 'handleValueChange'
| 'minStepsBetweenValues'
| 'onValueCommitted'
| 'percentageValues'
| 'registerSliderControl'
| 'setActive'
| 'setDragging'
| 'setValueState'
| 'step'
| 'subitems'
> {
/**
* The ref attached to the control area of the Slider.
*/
rootRef?: React.Ref<Element>;
}

export interface ReturnValue {
getRootProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from 'react';
import * as Slider from '@base_ui/react/Slider';
import { SliderProvider, type SliderProviderValue } from '@base_ui/react/Slider';
import { createRenderer, describeConformance } from '#test-utils';
import { SliderProvider } from '../Root/SliderProvider';

const NOOP = () => {};

describe('<Slider.Indicator />', () => {
const { render } = createRenderer();

const testProviderValue: SliderProviderValue = {
const testProviderValue: SliderProvider.Value = {
active: -1,
areValuesEqual: () => true,
axis: 'horizontal',
Expand Down
12 changes: 8 additions & 4 deletions packages/mui-base/src/Slider/Indicator/SliderIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import type { BaseUIComponentProps } from '../../utils/types';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import { useSliderContext } from '../Root/SliderProvider';
import { sliderStyleHookMapping } from '../Root/styleHooks';
import { SliderIndicatorProps } from './SliderIndicator.types';
import type { SliderRoot } from '../Root/SliderRoot';
import { useSliderIndicator } from './useSliderIndicator';

/**
*
* Demos:
Expand All @@ -18,8 +18,8 @@ import { useSliderIndicator } from './useSliderIndicator';
* - [SliderIndicator API](https://base-ui.netlify.app/components/react-slider/#api-reference-SliderIndicator)
*/
const SliderIndicator = React.forwardRef(function SliderIndicator(
props: SliderIndicatorProps,
forwardedRef: React.ForwardedRef<HTMLSpanElement>,
props: SliderIndicator.Props,
forwardedRef: React.ForwardedRef<HTMLElement>,
) {
const { render, className, ...otherProps } = props;

Expand Down Expand Up @@ -66,4 +66,8 @@ SliderIndicator.propTypes /* remove-proptypes */ = {
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export namespace SliderIndicator {
export interface Props extends BaseUIComponentProps<'span', SliderRoot.OwnerState> {}
}

export { SliderIndicator };
16 changes: 0 additions & 16 deletions packages/mui-base/src/Slider/Indicator/SliderIndicator.types.ts

This file was deleted.

34 changes: 26 additions & 8 deletions packages/mui-base/src/Slider/Indicator/useSliderIndicator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use client';
import * as React from 'react';
import { mergeReactProps } from '../../utils/mergeReactProps';
import {
UseSliderIndicatorParameters,
UseSliderIndicatorReturnValue,
} from './SliderIndicator.types';
import type { GenericHTMLProps } from '../../utils/types';
import type { useSliderRoot } from '../Root/useSliderRoot';

const axisProps = {
horizontal: {
Expand All @@ -21,9 +19,19 @@ const axisProps = {
},
};

function useSliderIndicator(
parameters: UseSliderIndicatorParameters,
): UseSliderIndicatorReturnValue {
/**
*
* Demos:
*
* - [Slider](https://mui.com/base-ui/react-slider/#hooks)
*
* API:
*
* - [useSliderIndicator API](https://mui.com/base-ui/react-slider/hooks-api/#use-slider-indicator)
*/
export function useSliderIndicator(
parameters: useSliderIndicator.Parameters,
): useSliderIndicator.ReturnValue {
const { axis, direction, orientation, percentageValues } = parameters;

const isRange = percentageValues.length > 1;
Expand Down Expand Up @@ -74,4 +82,14 @@ function useSliderIndicator(
);
}

export { useSliderIndicator };
export namespace useSliderIndicator {
export interface Parameters
extends Pick<
useSliderRoot.ReturnValue,
'axis' | 'direction' | 'disabled' | 'orientation' | 'percentageValues'
> {}

export interface ReturnValue {
getRootProps: (externalProps?: GenericHTMLProps) => GenericHTMLProps;
}
}
4 changes: 2 additions & 2 deletions packages/mui-base/src/Slider/Output/SliderOutput.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import { expect } from 'chai';
import * as Slider from '@base_ui/react/Slider';
import { SliderProvider, type SliderProviderValue } from '@base_ui/react/Slider';
import { createRenderer, describeConformance } from '#test-utils';
import { SliderProvider } from '../Root/SliderProvider';

const NOOP = () => {};

describe('<Slider.Output />', () => {
const { render } = createRenderer();

const testProviderValue: SliderProviderValue = {
const testProviderValue: SliderProvider.Value = {
active: -1,
areValuesEqual: () => true,
axis: 'horizontal',
Expand Down
10 changes: 7 additions & 3 deletions packages/mui-base/src/Slider/Output/SliderOutput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import type { BaseUIComponentProps } from '../../utils/types';
import { useComponentRenderer } from '../../utils/useComponentRenderer';
import { useSliderContext } from '../Root/SliderProvider';
import { sliderStyleHookMapping } from '../Root/styleHooks';
import { SliderOutputProps } from './SliderOutput.types';
import type { SliderRoot } from '../Root/SliderRoot';
import { useSliderOutput } from './useSliderOutput';

/**
*
* Demos:
Expand All @@ -18,7 +18,7 @@ import { useSliderOutput } from './useSliderOutput';
* - [SliderOutput API](https://base-ui.netlify.app/components/react-slider/#api-reference-SliderOutput)
*/
const SliderOutput = React.forwardRef(function SliderOutput(
props: SliderOutputProps,
props: SliderOutput.Props,
forwardedRef: React.ForwardedRef<HTMLOutputElement>,
) {
const { render, className, ...otherProps } = props;
Expand Down Expand Up @@ -64,4 +64,8 @@ SliderOutput.propTypes /* remove-proptypes */ = {
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
} as any;

export namespace SliderOutput {
export interface Props extends BaseUIComponentProps<'output', SliderRoot.OwnerState> {}
}

export { SliderOutput };
14 changes: 0 additions & 14 deletions packages/mui-base/src/Slider/Output/SliderOutput.types.ts

This file was deleted.

Loading

0 comments on commit b595967

Please sign in to comment.