-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed various UI components. #1451
Merged
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
aa9c55e
Organised CTA card settings panel
sanne-san a669fa9
Fixed Colour selection tests
ronaldlangeveld 68cbe9e
Added stopPropagation to Image Upload Form
ronaldlangeveld 3cf4452
Fixed image upload related tests and bugs
ronaldlangeveld 6538fbc
Updated CTA Card tests
ronaldlangeveld a762a4e
Fixed CTA Node tests
ronaldlangeveld d691484
Fixed linting
ronaldlangeveld 2eaba1d
Added button color as hex
ronaldlangeveld cc9490a
Added drag drop to CTA card img button
ronaldlangeveld 32a3ee9
Added img icon to color picker
ronaldlangeveld efc5d4a
Revert "Added img icon to color picker"
ronaldlangeveld 62adaf2
Fixed swatch test
ronaldlangeveld 29742de
Revert "Revert "Added img icon to color picker""
ronaldlangeveld 51f4a98
Added test for finding img icon
ronaldlangeveld 49b1443
Added image icon on Header
ronaldlangeveld d5b958d
Updated proptypes
ronaldlangeveld 09bb024
Added image string to headercard
ronaldlangeveld 3cc4b08
Improved button icon test
ronaldlangeveld 91860d2
Fixed console errors when inserting CTA card
kevinansfield 3ea83f2
Cleaned up repetition in `<MediaPlaceholder>`
kevinansfield c9f3dbe
Renamed call-to-action card test file
kevinansfield 60cb43a
Fixed errors coming from useMoveable
kevinansfield acc7d53
Fixed background color popover not closing on click outside
kevinansfield 69d31a8
Improved close on click outside for button color picker
kevinansfield a898422
Fixed display of button accent color in demo
kevinansfield 6f8074d
Fixed `return undefined` from React components in MediaPlaceholder
kevinansfield 9233c48
Merge branch 'main' into ui-updates-reorg
kevinansfield 917f349
Merge branch 'main' into ui-updates-reorg
kevinansfield bcef9be
Extracted modified UI components to beta copies
kevinansfield f327cb2
fixed CalloutCard background color setting layout
kevinansfield a67e9d7
fixed default button text color
kevinansfield 286ff6e
fixed tests
kevinansfield 11cf9a6
Removed tooltip from layout buttons in call to action card
sanne-san ec790b2
added missing prop types to <MediaUploaderBeta>
kevinansfield ba2fc95
avoid global Error override in MediaPlaceholderBeta.stories
kevinansfield 5c48803
renamed IconButton export in ButtonGroupBeta to avoid duplicate naming
kevinansfield 44b0feb
added missing prop types to ButtonGroupBeta
kevinansfield 467aee8
added default fn for `onRemoveMedia` prop to avoid errors if omitted
kevinansfield 993d118
Added a divider to call-to-action card settings panel
sanne-san 253f995
added isRequired to required props in ButtonGroupBeta
kevinansfield c18f8de
fixed incorrect borderStyle conditionals in MediaUploaderBeta
kevinansfield 044dd2b
added missing openImageEditor prop type to MediaUploaderBeta
kevinansfield 44e0a29
added roles and aria-checked to ButtonGroupBeta elements
kevinansfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/koenig-lexical/src/components/ui/ButtonGroupBeta.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
import {Tooltip} from './Tooltip'; | ||
import {usePreviousFocus} from '../../hooks/usePreviousFocus'; | ||
|
||
export function ButtonGroupBeta({buttons = [], selectedName, onClick, hasTooltip = true}) { | ||
return ( | ||
<div className="flex"> | ||
<ul className="flex items-center justify-evenly rounded-lg bg-grey-100 font-sans text-md font-normal text-white" role="menubar"> | ||
{buttons.map(({label, name, Icon, dataTestId, ariaLabel}) => ( | ||
<ButtonGroupIconButton | ||
key={`${name}-${label}`} | ||
ariaLabel={ariaLabel} | ||
dataTestId={dataTestId} | ||
hasTooltip={hasTooltip} | ||
Icon={Icon} | ||
label={label} | ||
name={name} | ||
selectedName={selectedName} | ||
onClick={onClick} | ||
/> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export function ButtonGroupIconButton({dataTestId, onClick, label, ariaLabel, name, selectedName, Icon, hasTooltip}) { | ||
const isActive = name === selectedName; | ||
|
||
const {handleMousedown, handleClick} = usePreviousFocus(onClick, name); | ||
|
||
return ( | ||
<li className="mb-0"> | ||
<button | ||
aria-checked={isActive} | ||
aria-label={ariaLabel || label} | ||
className={`group relative flex h-7 w-8 cursor-pointer items-center justify-center rounded-lg text-black dark:text-white dark:hover:bg-grey-900 ${isActive ? 'border border-grey-300 bg-white shadow-xs dark:bg-grey-900' : '' } ${Icon ? '' : 'text-[1.3rem] font-bold'}`} | ||
data-testid={dataTestId} | ||
role="menuitemradio" | ||
type="button" | ||
onClick={handleClick} | ||
onMouseDown={handleMousedown} | ||
> | ||
{Icon ? <Icon className="size-4 stroke-2" /> : label} | ||
{(Icon && label && hasTooltip) && <Tooltip label={label} />} | ||
</button> | ||
</li> | ||
); | ||
} | ||
|
||
ButtonGroupBeta.propTypes = { | ||
selectedName: PropTypes.oneOf(['regular', 'wide', 'full', 'split', 'center', 'left', 'small', 'medium', 'large', 'grid', 'list', 'minimal', 'immersive']).isRequired, | ||
hasTooltip: PropTypes.bool, | ||
onClick: PropTypes.func.isRequired, | ||
buttons: PropTypes.arrayOf(PropTypes.shape({ | ||
label: PropTypes.string, | ||
name: PropTypes.string.isRequired, | ||
Icon: PropTypes.elementType, | ||
dataTestId: PropTypes.string, | ||
ariaLabel: PropTypes.string | ||
})) | ||
}; |
48 changes: 48 additions & 0 deletions
48
packages/koenig-lexical/src/components/ui/ButtonGroupBeta.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import ImgFullIcon from '../../assets/icons/kg-img-full.svg?react'; | ||
import ImgRegularIcon from '../../assets/icons/kg-img-regular.svg?react'; | ||
import ImgWideIcon from '../../assets/icons/kg-img-wide.svg?react'; | ||
import React from 'react'; | ||
import {ButtonGroupBeta, ButtonGroupIconButton} from './ButtonGroupBeta'; | ||
|
||
const story = { | ||
title: 'Generic/Button group (beta)', | ||
component: ButtonGroupBeta, | ||
subcomponents: {ButtonGroupIconButton}, | ||
parameters: { | ||
status: { | ||
type: 'functional' | ||
} | ||
}, | ||
argTypes: { | ||
selectedName: {control: 'select', options: ['regular', 'wide', 'full']} | ||
} | ||
}; | ||
export default story; | ||
|
||
const Template = (args) => { | ||
return ( | ||
<ButtonGroupBeta {...args} /> | ||
); | ||
}; | ||
|
||
export const CardWidth = Template.bind({}); | ||
CardWidth.args = { | ||
selectedName: 'regular', | ||
buttons: [ | ||
{ | ||
label: 'Regular', | ||
name: 'regular', | ||
Icon: ImgRegularIcon | ||
}, | ||
{ | ||
label: 'Wide', | ||
name: 'wide', | ||
Icon: ImgWideIcon | ||
}, | ||
{ | ||
label: 'Full', | ||
name: 'full', | ||
Icon: ImgFullIcon | ||
} | ||
] | ||
}; |
93 changes: 93 additions & 0 deletions
93
packages/koenig-lexical/src/components/ui/ColorOptionButtonsBeta.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import PlusIcon from '../../assets/icons/plus.svg?react'; | ||
import React, {useState} from 'react'; | ||
import {Tooltip} from './Tooltip'; | ||
import {useClickOutside} from '../../hooks/useClickOutside'; | ||
import {usePreviousFocus} from '../../hooks/usePreviousFocus'; | ||
|
||
export function ColorOptionButtonsBeta({buttons = [], selectedName, onClick}) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const componentRef = React.useRef(null); | ||
|
||
const selectedButton = buttons.find(button => button.name === selectedName); | ||
|
||
// Close the swatch popover when clicking outside of it | ||
useClickOutside(isOpen, componentRef, () => setIsOpen(false)); | ||
|
||
return ( | ||
<div ref={componentRef} className="relative"> | ||
<button | ||
className={`relative size-6 cursor-pointer rounded-full ${selectedName ? 'p-[2px]' : 'border border-grey-200 dark:border-grey-800'}`} | ||
data-testid="color-options-button" | ||
type="button" | ||
onClick={() => setIsOpen(!isOpen)} | ||
> | ||
{selectedName && ( | ||
<div className="absolute inset-0 rounded-full bg-clip-content p-[3px]" style={{ | ||
background: 'conic-gradient(hsl(360,100%,50%),hsl(315,100%,50%),hsl(270,100%,50%),hsl(225,100%,50%),hsl(180,100%,50%),hsl(135,100%,50%),hsl(90,100%,50%),hsl(45,100%,50%),hsl(0,100%,50%))', | ||
WebkitMask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', | ||
WebkitMaskComposite: 'xor', | ||
mask: 'linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)', | ||
maskComposite: 'exclude' | ||
}} /> | ||
)} | ||
<span | ||
className={`${selectedButton?.color || ''} block size-full rounded-full border-2 border-white`} | ||
></span> | ||
</button> | ||
|
||
{/* Color options popover */} | ||
{isOpen && ( | ||
<div className="absolute -right-3 bottom-full z-10 mb-2 rounded-lg bg-white px-3 py-2 shadow" data-testid="color-options-popover"> | ||
<div className="flex"> | ||
<ul className="flex w-full items-center justify-between rounded-md font-sans text-md font-normal text-white"> | ||
{buttons.map(({label, name, color}) => ( | ||
name !== 'image' ? | ||
<ColorButton | ||
key={`${name}-${label}`} | ||
color={color} | ||
data-testid={`color-options-${name}-button`} | ||
label={label} | ||
name={name} | ||
selectedName={selectedName} | ||
onClick={(title) => { | ||
onClick(title); | ||
setIsOpen(false); | ||
}} | ||
/> | ||
: | ||
<li key='background-image' className={`mb-0 flex size-[3rem] cursor-pointer items-center justify-center rounded-full border-2 ${selectedName === name ? 'border-green' : 'border-transparent'}`} data-testid="background-image-color-button" type="button" onClick={() => onClick(name)}> | ||
<span className="border-1 flex size-6 items-center justify-center rounded-full border border-black/5"> | ||
<PlusIcon className="size-3 stroke-grey-700 stroke-2 dark:stroke-grey-500 dark:group-hover:stroke-grey-100" /> | ||
</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export function ColorButton({onClick, label, name, color, selectedName}) { | ||
const isActive = name === selectedName; | ||
|
||
const {handleMousedown, handleClick} = usePreviousFocus(onClick, name); | ||
return ( | ||
<li className="mb-0"> | ||
<button | ||
aria-label={label} | ||
className={`group relative flex size-6 cursor-pointer items-center justify-center rounded-full border-2 ${isActive ? 'border-green' : 'border-transparent'}`} | ||
data-test-id={`color-picker-${name}`} | ||
type="button" | ||
onClick={handleClick} | ||
onMouseDown={handleMousedown} | ||
> | ||
<span | ||
className={`${color} size-[1.8rem] rounded-full border`} | ||
></span> | ||
<Tooltip label={label} /> | ||
</button> | ||
</li> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Potential accessibility issue with Icon-only buttons.
When a button only has an icon (no visible text), ensure it always has an accessible name via
aria-label
. The current implementation falls back to the label if ariaLabel isn't provided, but there's a case where both could be missing.{Icon ? <Icon className="size-4 stroke-2" /> : label} {(Icon && label && hasTooltip) && <Tooltip label={label} />} + {(Icon && !label && !ariaLabel) && console.warn('ButtonGroupIconButton with Icon is missing both label and ariaLabel props')}