Newer
Older
import React, { useContext, useMemo, useState, useEffect } from 'react';
import { WaxContext, ReactDropDownStyles } from 'wax-prosemirror-core';
import Dropdown from 'react-dropdown';
import { v4 as uuidv4 } from 'uuid';
const Wrapper = styled.div`
${ReactDropDownStyles};
`;
const DropdownStyled = styled(Dropdown)`
display: inline-flex;
cursor: not-allowed;
opacity: ${props => (props.select ? 1 : 0.4)};
pointer-events: ${props => (props.select ? 'default' : 'none')};
.Dropdown-control {
&:hover {
box-shadow: none;
}
}
.Dropdown-arrow {
top: 17px;
}
.Dropdown-menu {
display: flex;
flex-direction: column;
align-items: flex-start;
.Dropdown-option {
width: 100%;
}
}
`;
// eslint-disable-next-line react/prop-types
const BlockDropDownComponent = ({ view, tools }) => {
const context = useContext(WaxContext);
const {
activeViewId,
pmViews: { main },
} = context;
const isEditable = main.props.editable(editable => {
return editable;
});
const translatedLabel = (translation, defaultLabel) => {
return !isEmpty(i18n) && i18n.exists(translation)
? t(translation)
: defaultLabel;
};
dropDownOptions.forEach(option => {
if (option.item.active(main.state, activeViewId)) {
setTimeout(() => {
setLabel(
translatedLabel(
`Wax.BlockLevel.${option.item.label}`,
option.item.label,
),
);
}, [
main.state.selection.$from.parent.type.name,
t('Wax.BlockLevel.Paragraph'),
]);
const MultipleDropDown = useMemo(
() => (
<Wrapper key={uuidv4()}>
<DropdownStyled
key={uuidv4()}
onChange={option => {
placeholder={translatedLabel(
'Wax.BlockLevel.Block Level',
'Heading styles',
)}