PointsToggle.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import {labelTypeAtom} from '@/demo/atoms';
  17. import {AddFilled, SubtractFilled} from '@carbon/icons-react';
  18. import {useAtom} from 'jotai';
  19. export default function PointsToggle() {
  20. const [labelType, setLabelType] = useAtom(labelTypeAtom);
  21. const isPositive = labelType === 'positive';
  22. const buttonStyle = (selected: boolean) =>
  23. `btn-md bg-graydark-800 !text-white md:px-2 lg:px-4 py-0.5 ${selected ? `border border-white hover:bg-graydark-800` : `border-graydark-700 hover:bg-graydark-700`}`;
  24. return (
  25. <div className="flex items-center w-full md:ml-2">
  26. <div className="join group grow gap-[1px]">
  27. <button
  28. className={`w-1/2 btn join-item text-white ${buttonStyle(isPositive)}`}
  29. onClick={() => setLabelType('positive')}>
  30. <AddFilled size={24} className="text-blue-500" /> Add
  31. </button>
  32. <button
  33. className={`w-1/2 btn join-item text-red-700 ${buttonStyle(!isPositive)}`}
  34. onClick={() => setLabelType('negative')}>
  35. <SubtractFilled size={24} className="text-red-400" />
  36. Remove
  37. </button>
  38. </div>
  39. </div>
  40. );
  41. }