fleet/frontend/components/forms/fields/Slider/Slider.tsx
Gabriel Hernandez 0491c730ac
Feat UI mdm migration (#11732)
relates to #11669

Implements the UI for the end-user migration workflow. This includes:

UI for migration form:


![image](https://github.com/fleetdm/fleet/assets/1153709/5f2959a3-efd9-4a4a-9aef-83025d5e23a4)

Preview payload modal:


![image](https://github.com/fleetdm/fleet/assets/1153709/aee580f4-c570-447f-8a99-c7f2a8f3dab8)

Mdm setup state:


![image](https://github.com/fleetdm/fleet/assets/1153709/09b8210a-b4e6-4407-86de-fd439de0841e)

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality.
2023-05-17 17:32:55 +01:00

64 lines
1.5 KiB
TypeScript

import React from "react";
import classnames from "classnames";
import { pick } from "lodash";
import FormField from "components/forms/FormField";
import { IFormFieldProps } from "components/forms/FormField/FormField";
interface ISliderProps {
onChange: () => void;
value: boolean;
inactiveText: string;
activeText: string;
className?: string;
}
const baseClass = "fleet-slider";
const Slider = (props: ISliderProps): JSX.Element => {
const { onChange, value, inactiveText, activeText } = props;
const sliderBtnClass = classnames(baseClass, {
[`${baseClass}--active`]: value,
});
const sliderDotClass = classnames(`${baseClass}__dot`, {
[`${baseClass}__dot--active`]: value,
});
const handleClick = (evt: React.MouseEvent) => {
evt.preventDefault();
return onChange();
};
const formFieldProps = pick(props, [
"hint",
"label",
"error",
"name",
"className",
]) as IFormFieldProps;
return (
<FormField {...formFieldProps} type="slider">
<div className={`${baseClass}__wrapper`}>
<button
className={`button button--unstyled ${sliderBtnClass}`}
onClick={handleClick}
>
<div className={sliderDotClass} />
</button>
<span
className={`${baseClass}__label ${baseClass}__label--${
value ? "active" : "inactive"
}`}
>
{value ? activeText : inactiveText}
</span>
</div>
</FormField>
);
};
export default Slider;