Compare commits

...

21 Commits

Author SHA1 Message Date
doprz
4f2a29f268 chore: fix lint errors 2024-09-30 19:31:17 -05:00
doprz
d5c3d32170 Merge branch 'derek/experimental' of https://github.com/DereC4/UT-Registration-Plus into DereC4-derek/experimental 2024-09-30 19:20:03 -05:00
9356357545 Merge branch 'Longhorn-Developers:main' into derek/experimental 2024-09-29 14:59:26 -05:00
0d63c66356 fix: styling 2024-09-08 12:46:26 -05:00
703a0fa596 feat: button custom function prop 2024-09-04 13:05:31 -05:00
7acc91f4ee chore: fix lint 2024-09-04 12:50:06 -05:00
5d9980cac3 feat: using type now 2024-09-04 12:43:45 -05:00
57832b0dd4 fix: story 2024-09-04 12:43:08 -05:00
b9358803dd feat: look at how this switch goes back and forth very mindful very demure 2024-09-04 12:27:12 -05:00
4397dfb1c5 feat: switch button initial test 2024-09-04 12:25:16 -05:00
0e70bbd52f Merge branch 'Longhorn-Developers:main' into main 2024-06-04 01:14:35 -05:00
79f2ffa4cc Merge branch 'Longhorn-Developers:main' into main 2024-05-27 18:26:05 -05:00
c330e3123a Merge branch 'Longhorn-Developers:main' into master 2024-05-21 21:46:06 -05:00
38d09e4aae Merge branch 'Longhorn-Developers:main' into master 2024-04-16 15:15:38 -05:00
98a7cc618b Merge branch 'Longhorn-Developers:main' into master 2024-04-09 14:04:09 -05:00
74cc6e6da1 fix: importance (tailwind wise) 2024-03-29 00:51:25 -05:00
c68b017462 Merge branch 'Longhorn-Developers:main' into master 2024-03-29 00:44:18 -05:00
aeb19cff54 fix: text-ut-burntorange 2024-03-25 15:50:59 -05:00
5a73c8ee6c fix: change color again 2024-03-25 15:17:40 -05:00
35b0d01c51 fix: change color hex 2024-03-25 15:16:30 -05:00
b84cf7c15d fix: font weight added 2024-03-25 15:14:52 -05:00
2 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react';
import SwitchButton from '@views/components/common/SwitchButton';
const meta = {
title: 'Components/Common/SwitchButton',
component: SwitchButton,
tags: ['autodocs'],
parameters: {
layout: 'centered',
},
} satisfies Meta<typeof SwitchButton>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
isChecked: true,
},
};

View File

@@ -0,0 +1,47 @@
import { Switch } from '@headlessui/react';
import React, { useEffect, useState } from 'react';
type ToggleSwitchProps = {
isChecked?: boolean;
onChange?: (checked: boolean) => void;
};
/**
* A custom switch button component.
*
* @component
* @param {Object} props - The component props.
* @param {boolean} [props.isChecked=true] - The initial checked state of the switch button.
* @param {Function} props.onChange - The callback function to be called when the switch button is toggled.
* @returns {JSX.Element} The rendered SwitchButton component.
*/
const SwitchButton = ({ isChecked = true, onChange }: ToggleSwitchProps): JSX.Element => {
const [enabled, setEnabled] = useState(isChecked);
useEffect(() => {
setEnabled(isChecked);
}, [isChecked]);
const handleChange = (checked: boolean) => {
setEnabled(checked);
if (onChange) {
onChange(checked);
}
};
return (
<Switch
checked={enabled}
onChange={handleChange}
className={`${enabled ? 'bg-[#579D42]' : 'bg-gray-400'}
relative inline-flex items-center h-8 w-13 rounded-full transition-colors ease-in-out duration-200`}
>
<span
className={`${enabled ? 'translate-x-6' : 'translate-x-1'}
inline-block w-6 h-6 transform bg-white rounded-full transition-transform ease-in-out duration-200`}
/>
</Switch>
);
};
export default SwitchButton;