diff --git a/src/Form/atoms/SliderInput.tsx b/src/Form/atoms/SliderInput.tsx
index d9c71bcf8..7fbead1de 100644
--- a/src/Form/atoms/SliderInput.tsx
+++ b/src/Form/atoms/SliderInput.tsx
@@ -61,7 +61,7 @@ const Mark = styled.span<{leftValue: number}>`
background-color: hsl(205, 77%, 64%);
`;
-const MarkLabel = styled.span<{leftValue: number, alignment?: IMartAlignment,}>`
+const MarkLabel = styled.span<{leftValue: number, alignment?: IMarkAlignment}>`
position: absolute;
top: -24px;
left: ${({leftValue}) => `calc(${leftValue}% + 7px)`};
@@ -161,7 +161,7 @@ const valueToPercent = (value: number, min: number, max: number) : number => {
// };
-const getMarkAlignment = (value: number, min: number, max: number) : IMartAlignment => {
+const getMarkAlignment = (value: number, min: number, max: number) : IMarkAlignment => {
if(value === min) {
return 'right';
}
@@ -173,7 +173,7 @@ const getMarkAlignment = (value: number, min: number, max: number) : IMartAlignm
return 'center';
};
-const renderMarks = (markList: ISliderMark[], min: number, max: number, listTag: string) => {
+const renderMarks = (markList: ISliderMark[], min: number, max: number, listTag: string, allMarkCentered?: boolean) => {
const listOptions : JSX.Element[] = [];
const marksElements = markList.map(({value, label}, index) => {
@@ -189,7 +189,7 @@ const renderMarks = (markList: ISliderMark[], min: number, max: number, listTag:
/>
{label}
@@ -208,7 +208,7 @@ const renderMarks = (markList: ISliderMark[], min: number, max: number, listTag:
};
-export type IMartAlignment = 'left' | 'center' | 'right';
+export type IMarkAlignment = 'left' | 'center' | 'right';
export interface ISliderMark {
value: number
@@ -227,6 +227,7 @@ interface ISliderOwnProps {
showValue?: boolean
inputCallback?: (value: number) => void
onChangeCallback?: (value: number) => void
+ allMarkCentered?: boolean
}
export type ISlider = ISliderOwnProps & InputHTMLAttributes;
@@ -243,6 +244,7 @@ const SliderInput : React.FC = ({
onlyMarkSelect = false,
inputCallback = () => {},
onChangeCallback = () => {},
+ allMarkCentered = false,
...props
}) => {
@@ -316,7 +318,7 @@ const SliderInput : React.FC = ({
- {marks && renderMarks(marks, minValid, maxValid, `sliderList-${minValid}-${maxValid}`)}
+ {marks && renderMarks(marks, minValid, maxValid, `sliderList-${minValid}-${maxValid}`, allMarkCentered)}
{isGhostActive && onlyMarkSelect
? (
`
font-size: 14px;
color: hsl(207, 5%, 57%);
display: flex;
justify-content: space-between;
margin-bottom: 20px;
- padding: 0 6px;
+ ${({allMarkCentered}) => allMarkCentered ?
+ `padding: 0;`
+ :
+ `padding: 0 6px;`
+ };
`;
const ValueTitle = styled(Label)`
@@ -53,6 +57,7 @@ interface IPercentageSliderProps {
inputCallback?: (value: number) => void
updateThumbColor?: (value: number) => IFeedbackColor
updateTitle?: (value: number) => string
+ allMarkCentered?: boolean
}
type IPercentageSlider = IPercentageSliderProps & InputHTMLAttributes;
@@ -65,6 +70,7 @@ const PercentageSlider: React.FC = (
updateThumbColor,
updateTitle,
showValue,
+ allMarkCentered,
...props
}
) => {
@@ -79,7 +85,7 @@ const PercentageSlider: React.FC = (
return(
-
+
);
diff --git a/storybook/src/stories/Form/Input/PercentageSlider.stories.tsx b/storybook/src/stories/Form/Input/PercentageSlider.stories.tsx
index 7d1a7b3e0..76f898bda 100644
--- a/storybook/src/stories/Form/Input/PercentageSlider.stories.tsx
+++ b/storybook/src/stories/Form/Input/PercentageSlider.stories.tsx
@@ -39,7 +39,7 @@ const exampleMarks : ISliderMark[] = [
label:'100%',
},
];
-
+
export const _PercentageSlider = () => {
const title = text('Title', 'Duration');
const disabled = boolean('Disabled', false);
@@ -49,6 +49,7 @@ export const _PercentageSlider = () => {
const showValue = action('Input Callback');
const marks = object('Marks', exampleMarks);
const showTitle = boolean("Show Value", true);
+ const allMarkCentered = boolean('Center all mark values', false);
// const step = number('Step', 1); // still fixing step option
const handleUpdate = (value: number) => {
@@ -60,11 +61,11 @@ export const _PercentageSlider = () => {
if(value <= 20) {
return 'neutral';
}
-
+
if((value > 20) && (value <= 80)) {
return 'info';
}
-
+
return 'error';
}
@@ -72,11 +73,11 @@ export const _PercentageSlider = () => {
if(value <= 20) {
return 'Small sound';
}
-
+
if((value > 20) && (value <= 80)) {
return 'Normal sound';
}
-
+
return 'Dangerous sound';
}
@@ -92,6 +93,7 @@ export const _PercentageSlider = () => {
updateThumbColor={customThumb ? otherColorHandler : undefined }
updateTitle={customTitle ? otherTitlesHandler : undefined}
showValue={showTitle}
+ allMarkCentered={allMarkCentered}
/>
)
diff --git a/storybook/src/stories/Form/Input/SliderInput.stories.tsx b/storybook/src/stories/Form/Input/SliderInput.stories.tsx
index da1f2954a..9030d410a 100644
--- a/storybook/src/stories/Form/Input/SliderInput.stories.tsx
+++ b/storybook/src/stories/Form/Input/SliderInput.stories.tsx
@@ -51,7 +51,7 @@ const exampleMarks : ISliderMark[] = [
label:'8H',
},
];
-
+
export const _SliderInput = () => {
const disabled = boolean('Disabled', false);
@@ -60,6 +60,7 @@ export const _SliderInput = () => {
const defaultValue = number('Default value', 6)
const showValue = action('Input Callback');
const marks = object('Marks', exampleMarks);
+ const allMarkCentered = boolean('Center aligned end numbers', false);
// const step = number('Step', 1); // still fixing step option
const handleUpdate = (value: number) => {
@@ -77,6 +78,7 @@ export const _SliderInput = () => {
inputCallback={handleUpdate}
marks={marks}
defaultValue={defaultValue}
+ allMarkCentered={allMarkCentered}
/>
)