Skip to content

Commit

Permalink
feat: introduce slider component description
Browse files Browse the repository at this point in the history
  • Loading branch information
Arucard89 committed May 8, 2024
1 parent d96c7d1 commit a54384a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/content/components/uikit/Slider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import dynamic from 'next/dynamic';

import {Repos} from '../../../../types/common';
import {getGithubUrl, getReadmeUrl, mappingOptions} from '../../utils';

const getterOptions = {repoName: Repos.Uikit, componentName: 'Slider'};

export const sliderConfig = {
id: 'slider',
title: 'Slider',
githubUrl: getGithubUrl(getterOptions),
content: {
readmeUrl: getReadmeUrl(getterOptions),
},
sandbox: {
component: dynamic(() => import('../examples/components').then((mod) => mod.SliderExample)),
props: {
hasTooltip: {
type: 'switch',
defaultValue: false,
},
disabled: {
type: 'switch',
defaultValue: false,
},
validationState: {
type: 'radioButton',
values: mappingOptions(['normal', 'invalid']),
defaultValue: 'normal',
},
errorMessage: {
type: 'input',
defaultValue: 'Input is invalid',
},
size: {
type: 'radioButton',
values: mappingOptions(['s', 'm', 'l', 'xl']),
defaultValue: 'm',
},
min: {
type: 'input',
defaultValue: 0,
},
max: {
type: 'input',
defaultValue: 100,
},
step: {
type: 'input',
defaultValue: 1,
},
debounceDelay: {
type: 'input',
defaultValue: 0,
},
marksCount: {
type: 'input',
defaultValue: 2,
},
},
},
};
48 changes: 48 additions & 0 deletions src/content/components/uikit/examples/components/SliderExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Slider, SliderProps} from '@gravity-ui/uikit';
import React from 'react';

type SliderExampleProps = Omit<
SliderProps,
'max' | 'min' | 'marksCount' | 'step' | 'debounceDelay'
> & {
max?: string | number;
min?: string | number;
marksCount?: string | number;
step?: string | number;
debounceDelay?: string | number;
};

export const SliderExample = ({
defaultValue,
max,
min,
marksCount,
step,
debounceDelay,
...restProps
}: SliderExampleProps) => {
const [value, setValue] = React.useState(defaultValue);
const maxValue = Number(max) || undefined;
const minValue = Number(min) || undefined;
const marksCountValue = Number(marksCount) || undefined;
const stepValue = Number(step) || undefined;
const debounceDelayValue = Number(debounceDelay) || undefined;

return (
<div style={{width: '100%', maxWidth: 300}}>
<Slider
{...restProps}
onUpdate={setValue}
min={minValue}
max={maxValue}
marksCount={marksCountValue}
step={stepValue}
debounceDelay={debounceDelayValue}
defaultValue={defaultValue}
/>
<div style={{textAlign: 'center'}}>{`Selected value: ${
value === undefined ? '' : value
}`}</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/content/components/uikit/examples/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './ArrowToggleExample';
export * from './PopupAnchorExample';
export * from './PopupPlacementExample';
export * from './SliderExample';
2 changes: 2 additions & 0 deletions src/content/components/uikit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {radioGroupConfig} from './RadioGroup';
import {selectConfig} from './Select';
import {sheetConfig} from './Sheet';
import {skeletonConfig} from './Skeleton';
import {sliderConfig} from './Slider';
import {spinConfig} from './Spin';
import {switchConfig} from './Switch';
import {tableConfig} from './Table';
Expand Down Expand Up @@ -69,6 +70,7 @@ const uikitComponents: Component[] = [
radioGroupConfig,
selectConfig,
skeletonConfig,
sliderConfig,
spinConfig,
switchConfig,
tableConfig,
Expand Down

0 comments on commit a54384a

Please sign in to comment.