-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20964c3
commit bdfa907
Showing
3 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/volto-logos-block/src/components/widgets/ButtonsWidget.tsx
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,77 @@ | ||
import React from 'react'; | ||
|
||
import FormFieldWrapper from '@plone/volto/components/manage/Widgets/FormFieldWrapper'; | ||
import Icon from '@plone/volto/components/theme/Icon/Icon'; | ||
import { Button } from '@plone/components'; | ||
import { isEqual, find } from 'lodash'; | ||
|
||
// Move to an unified `StyleDefinition` type | ||
type Actions = | ||
| { | ||
name: string; | ||
label: string; | ||
style: Record<`--${string}`, string>; | ||
} | ||
| { | ||
name: string; | ||
label: string; | ||
style: undefined; | ||
}; | ||
|
||
export type ButtonsWidgetProps = { | ||
id: string; | ||
onChange: Function; | ||
actions: Actions[]; | ||
actionsInfoMap: Record<string, string[]>; | ||
filterActions: string[]; | ||
value: string; | ||
default: string; | ||
disabled: boolean; | ||
isDisabled: boolean; | ||
}; | ||
|
||
const ButtonsWidget = (props: ButtonsWidgetProps) => { | ||
const { disabled, id, onChange, actions, actionsInfoMap, value, isDisabled } = | ||
props; | ||
|
||
React.useEffect(() => { | ||
if (!props.value && props.default) { | ||
props.onChange( | ||
props.id, | ||
find(actions, { name: props.default })?.style || props.default, | ||
); | ||
} | ||
}); | ||
|
||
return ( | ||
<FormFieldWrapper {...props} className="widget"> | ||
<div className="buttons buttons-widget"> | ||
{actions.map((action) => ( | ||
<Button | ||
key={action.name} | ||
aria-label={actionsInfoMap[action.name][1]} | ||
onPress={() => onChange(id, action.style || action.name)} | ||
className={ | ||
isEqual(value, action.style || action.name) ? 'active' : null | ||
} | ||
isDisabled={disabled || isDisabled} | ||
> | ||
{typeof actionsInfoMap[action.name][0] === 'string' ? ( | ||
<div className="image-sizes-text"> | ||
{actionsInfoMap[action.name][0]} | ||
</div> | ||
) : ( | ||
<Icon | ||
name={actionsInfoMap[action.name][0]} | ||
title={actionsInfoMap[action.name][1] || action.name} | ||
size="24px" | ||
/> | ||
)} | ||
</Button> | ||
))} | ||
</div> | ||
</FormFieldWrapper> | ||
); | ||
}; | ||
|
||
export default ButtonsWidget; |
4 changes: 1 addition & 3 deletions
4
packages/volto-logos-block/src/components/widgets/LogoBlockSizeWidget.tsx
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