feat(toolbar): new Toolbar to enable reactive state synchronization (#3983)

This commit is contained in:
Alireza authored and GitHub committed 2024-03-27 16:01:32 -04:00
1 parent 79d5c36bda
commit 566b25a544
155 files changed
+6311 -6577

No files matched your search

@@ -1,13 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import IconButton from '../IconButton';
import Icon from '../Icon';
import Tooltip from '../Tooltip';
const ToolbarButton = ({
type = 'tool',
id,
icon,
label,
@@ -15,47 +13,37 @@ const ToolbarButton = ({
onInteraction,
dropdownContent,
//
isActive,
className,
size,
toolTipClassName,
...rest
//
}) => {
const classes = {
tool: isActive
? 'text-black'
: 'text-common-bright hover:!bg-primary-dark hover:text-primary-light',
toggle: isActive
? '!text-[#348CFD]'
: 'text-common-bright hover:!bg-primary-dark hover:text-primary-light',
action: isActive
? 'text-black'
: 'text-common-bright hover:!bg-primary-dark hover:text-primary-light',
};
const bgClasses = {
toggle: isActive && 'bg-transparent',
};
const activeClass = isActive ? 'active' : '';
const shouldShowDropdown = !!isActive && !!dropdownContent;
const shouldShowDropdown = !!dropdownContent;
const iconEl = icon ? <Icon name={icon} /> : <div>{label || 'Missing icon and label'}</div>;
const sizeToUse = size ?? 'toolbar';
const toolTipClassNameToUse =
toolTipClassName !== undefined
? toolTipClassName
: sizeToUse === 'toolbar'
? 'w-[40px] h-[40px]'
: 'w-[32px] h-[32px]';
return (
<div key={id}>
<Tooltip
isSticky={shouldShowDropdown}
content={shouldShowDropdown ? dropdownContent : label}
tight={shouldShowDropdown}
className={toolTipClassNameToUse}
>
<IconButton
variant={isActive ? 'contained' : 'text'}
bgColor={bgClasses[type]}
size="toolbar"
className={classnames(activeClass, classes[type], className)}
size={sizeToUse}
className={className}
onClick={() => {
onInteraction({
itemId: id,
interactionType: type,
commands,
});
}}
@@ -73,27 +61,20 @@ const ToolbarButton = ({
ToolbarButton.defaultProps = {
dropdownContent: null,
isActive: false,
type: 'action',
};
ToolbarButton.propTypes = {
/* Influences background/hover styling */
type: PropTypes.oneOf(['action', 'toggle', 'tool']),
id: PropTypes.string.isRequired,
isActive: PropTypes.bool,
className: PropTypes.string,
commands: PropTypes.arrayOf(
PropTypes.shape({
commandName: PropTypes.string.isRequired,
commandOptions: PropTypes.object,
})
),
onInteraction: PropTypes.func.isRequired,
commands: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
onInteraction: PropTypes.func,
icon: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
/** Tooltip content can be replaced for a customized content by passing a node to this value. */
dropdownContent: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
size: PropTypes.string,
toolTipClassName: PropTypes.string,
};
export default ToolbarButton;