import React, { useState, useRef, createRef } from 'react'; import { action } from '@storybook/addon-actions'; import LabelColors from 'shared/constants/labelColors'; import LabelManager from 'shared/components/PopupMenu/LabelManager'; import LabelEditor from 'shared/components/PopupMenu/LabelEditor'; import ListActions from 'shared/components/ListActions'; import MemberManager from 'shared/components/MemberManager'; import DueDateManager from 'shared/components/DueDateManager'; import MiniProfile from 'shared/components/MiniProfile'; import styled from 'styled-components'; import PopupMenu, { PopupProvider, usePopup, Popup } from '.'; import NormalizeStyles from 'App/NormalizeStyles'; import BaseStyles from 'App/BaseStyles'; import produce from 'immer'; export default { component: PopupMenu, title: 'PopupMenu', parameters: { backgrounds: [ { name: 'white', value: '#ffffff', default: true }, { name: 'gray', value: '#f8f8f8' }, ], }, }; const labelData = [ { labelId: 'development', name: 'Development', labelColor: { id: '1', name: 'white', colorHex: LabelColors.BLUE, position: 1, }, active: false, }, { labelId: 'general', name: 'General', labelColor: { id: '1', name: 'white', colorHex: LabelColors.PINK, position: 1, }, active: false, }, ]; const OpenLabelBtn = styled.span``; type TabProps = { tab: number; }; const LabelManagerEditor = () => { const [labels, setLabels] = useState(labelData); const [currentLabel, setCurrentLabel] = useState(''); const { setTab } = usePopup(); return ( <> { setTab(2); }} onLabelEdit={labelId => { setCurrentLabel(labelId); setTab(1); }} onLabelToggle={labelId => { setLabels( produce(labels, draftState => { const idx = labels.findIndex(label => label.labelId === labelId); if (idx !== -1) { draftState[idx] = { ...draftState[idx], active: !labels[idx].active }; } }), ); }} /> label.labelId === currentLabel) ?? null} onLabelEdit={(_labelId, name, color) => { setLabels( produce(labels, draftState => { const idx = labels.findIndex(label => label.labelId === currentLabel); if (idx !== -1) { draftState[idx] = { ...draftState[idx], name, labelColor: color }; } }), ); setTab(0); }} /> { setLabels([...labels, { labelId: name, name, labelColor: color, active: false }]); setTab(0); }} /> ); }; const OpenLabelsButton = () => { const $buttonRef = createRef(); const [currentLabel, setCurrentLabel] = useState(''); const [labels, setLabels] = useState(labelData); const { showPopup, setTab } = usePopup(); console.log(labels); return ( { showPopup($buttonRef, ); }} > Open ); }; export const LabelsPopup = () => { const [isPopupOpen, setPopupOpen] = useState(false); return ( ); }; export const LabelsLabelEditor = () => { const [isPopupOpen, setPopupOpen] = useState(false); return ( <> {isPopupOpen && ( setPopupOpen(false)} left={10} > )} ); }; const initalState = { left: 0, top: 0, isOpen: false }; export const ListActionsPopup = () => { const $buttonRef = useRef(null); const [popupData, setPopupData] = useState(initalState); return ( <> {popupData.isOpen && ( setPopupData(initalState)} left={popupData.left} > )} ); }; export const MemberManagerPopup = () => { const $buttonRef = useRef(null); const [popupData, setPopupData] = useState(initalState); return ( <> {popupData.isOpen && ( setPopupData(initalState)} left={popupData.left}> )} { if ($buttonRef && $buttonRef.current) { const pos = $buttonRef.current.getBoundingClientRect(); setPopupData({ isOpen: true, left: pos.left, top: pos.top + pos.height + 10, }); } }} > Open ); }; export const DueDateManagerPopup = () => { const $buttonRef = useRef(null); const [popupData, setPopupData] = useState(initalState); return ( <> {popupData.isOpen && ( setPopupData(initalState)} left={popupData.left}> )} { if ($buttonRef && $buttonRef.current) { const pos = $buttonRef.current.getBoundingClientRect(); setPopupData({ isOpen: true, left: pos.left, top: pos.top + pos.height + 10, }); } }} > Open ); }; export const MiniProfilePopup = () => { const $buttonRef = useRef(null); const [popupData, setPopupData] = useState(initalState); return ( <> {popupData.isOpen && ( setPopupData(initalState)} left={popupData.left} > )} { if ($buttonRef && $buttonRef.current) { const pos = $buttonRef.current.getBoundingClientRect(); setPopupData({ isOpen: true, left: pos.left, top: pos.top + pos.height + 10, }); } }} > Open ); };