Skip to content
Snippets Groups Projects
Commit 74678e8f authored by chris's avatar chris
Browse files

add drop down icon

parent 6afe8fbd
No related branches found
No related tags found
1 merge request!458Hhmi accessibility
...@@ -484,4 +484,10 @@ export default { ...@@ -484,4 +484,10 @@ export default {
<path d="M12 2A10 10 0 1 0 22 12A10 10 0 0 0 12 2M18 11H13L14.81 9.19A3.94 3.94 0 0 0 12 8A4 4 0 1 0 15.86 13H17.91A6 6 0 1 1 12 6A5.91 5.91 0 0 1 16.22 7.78L18 6Z" />{' '} <path d="M12 2A10 10 0 1 0 22 12A10 10 0 0 0 12 2M18 11H13L14.81 9.19A3.94 3.94 0 0 0 12 8A4 4 0 1 0 15.86 13H17.91A6 6 0 1 1 12 6A5.91 5.91 0 0 1 16.22 7.78L18 6Z" />{' '}
</Svg> </Svg>
), ),
expand: ({ className }) => (
<Svg className={className} fill="none" viewBox="0 0 24 24">
<title> Expand</title>
<path d="M7 10l5 5 5-5z" />{' '}
</Svg>
),
}; };
/* eslint-disable react/jsx-props-no-spreading */ /* eslint-disable react/jsx-props-no-spreading */
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React, { useMemo, useContext, useState, useEffect } from 'react'; import React, {
useMemo,
useContext,
useState,
useEffect,
useRef,
createRef,
} from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import * as tablesFn from 'prosemirror-tables'; import * as tablesFn from 'prosemirror-tables';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext, Icon } from 'wax-prosemirror-core';
const Wrapper = styled.div` const Wrapper = styled.div`
opacity: ${props => (props.disabled ? '0.4' : '1')}; opacity: ${props => (props.disabled ? '0.4' : '1')};
...@@ -14,9 +21,15 @@ const DropDownButton = styled.button` ...@@ -14,9 +21,15 @@ const DropDownButton = styled.button`
background: #fff; background: #fff;
border: none; border: none;
color: #000; color: #000;
cursor: pointer;
display: flex; display: flex;
position: relative; position: relative;
width: 160px; width: 160px;
span {
position: relative;
top: 2px;
}
`; `;
const DropDownMenu = styled.div` const DropDownMenu = styled.div`
...@@ -26,7 +39,7 @@ const DropDownMenu = styled.div` ...@@ -26,7 +39,7 @@ const DropDownMenu = styled.div`
border: 1px solid #ddd; border: 1px solid #ddd;
border-radius: 0.25rem; border-radius: 0.25rem;
box-shadow: 0 0.2rem 0.4rem rgb(0 0 0 / 10%); box-shadow: 0 0.2rem 0.4rem rgb(0 0 0 / 10%);
margin: 0.8rem auto auto; margin: 10px auto auto;
position: fixed; position: fixed;
width: 170px; width: 170px;
z-index: 2; z-index: 2;
...@@ -42,6 +55,12 @@ const DropDownMenu = styled.div` ...@@ -42,6 +55,12 @@ const DropDownMenu = styled.div`
} }
`; `;
const StyledIcon = styled(Icon)`
height: 18px;
width: 18px;
margin-left: auto;
`;
const TableDropDown = ({ item }) => { const TableDropDown = ({ item }) => {
const dropDownOptions = [ const dropDownOptions = [
{ label: 'Add column before', value: 'addColumnBefore' }, { label: 'Add column before', value: 'addColumnBefore' },
...@@ -59,16 +78,16 @@ const TableDropDown = ({ item }) => { ...@@ -59,16 +78,16 @@ const TableDropDown = ({ item }) => {
]; ];
const { activeView } = useContext(WaxContext); const { activeView } = useContext(WaxContext);
const [selectedOption, setSelectedOption] = useState(''); const itemRefs = useRef([]);
const itemRefs = React.useRef([]);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const isDisabled = !item.select(activeView.state); const isDisabled = !item.select(activeView.state);
useEffect(() => {}, [selectedOption]); useEffect(() => {
if (isDisabled) setIsOpen(false);
}, [isDisabled]);
const openCloseMenu = e => { const openCloseMenu = e => {
// e.preventDefault(); // e.preventDefault();
if (!isDisabled) setIsOpen(!isOpen); if (!isDisabled) setIsOpen(!isOpen);
}; };
...@@ -117,15 +136,14 @@ const TableDropDown = ({ item }) => { ...@@ -117,15 +136,14 @@ const TableDropDown = ({ item }) => {
tabIndex="0" tabIndex="0"
type="button" type="button"
> >
Table Options <span>Table Options</span> <StyledIcon name="expand" />
</DropDownButton> </DropDownButton>
<DropDownMenu <DropDownMenu
role="menu" role="menu"
style={{ visibility: isOpen ? 'visible' : 'hidden' }} style={{ visibility: isOpen ? 'visible' : 'hidden' }}
> >
{dropDownOptions.map((option, index) => { {dropDownOptions.map((option, index) => {
itemRefs.current[index] = itemRefs.current[index] = itemRefs.current[index] || createRef();
itemRefs.current[index] || React.createRef();
return ( return (
<span <span
key={option.value} key={option.value}
...@@ -135,7 +153,6 @@ const TableDropDown = ({ item }) => { ...@@ -135,7 +153,6 @@ const TableDropDown = ({ item }) => {
activeView.dispatch, activeView.dispatch,
tablesFn[option.value], tablesFn[option.value],
); );
setSelectedOption(option.value);
setTimeout(() => { setTimeout(() => {
activeView.focus(); activeView.focus();
...@@ -154,37 +171,10 @@ const TableDropDown = ({ item }) => { ...@@ -154,37 +171,10 @@ const TableDropDown = ({ item }) => {
</DropDownMenu> </DropDownMenu>
</Wrapper> </Wrapper>
), ),
[isDisabled, isOpen, selectedOption], [isDisabled, isOpen],
); );
return TableDropDownComponent; return TableDropDownComponent;
// const TableDropDownComponent = useMemo(
// () => (
// <Wrapper>
// <DropdownStyled
// onChange={option => {
// item.run(
// activeView.state,
// activeView.dispatch,
// tablesFn[option.value],
// );
// setSelectedOption(option.value);
// setTimeout(() => {
// activeView.focus();
// });
// }}
// options={appliedDropDownOptions}
// placeholder="Table Options"
// select={isDisabled}
// />
// </Wrapper>
// ),
// [isDisabled, selectedOption, appliedDropDownOptions],
// );
// return TableDropDownComponent;
}; };
export default TableDropDown; export default TableDropDown;
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment