Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
crossorigin="anonymous">
<link rel="icon" href="/OpenWebSheet/favicon.ico">
<title>Open web sheet</title>
<script type="module" crossorigin src="/OpenWebSheet/assets/index-BChN-qVl.js"></script>
<script type="module" crossorigin src="/OpenWebSheet/assets/index-DrD1_fGU.js"></script>
<link rel="stylesheet" crossorigin href="/OpenWebSheet/assets/index-Cs_txOUy.css">
</head>
<body>
Expand Down
26 changes: 16 additions & 10 deletions src/features/ribbon/FormatControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ interface FormatControlsProps {
onAction: (action: AppAction) => void;
}

const alignments = [
{icon: 'fa fa-align-left', label: 'Align left', value: 'left', textAlign: TextAlign.Left},
{icon: 'fa fa-align-center', label: 'Align center', value: 'center', textAlign: TextAlign.Center},
{icon: 'fa fa-align-right', label: 'Align right', value: 'right', textAlign: TextAlign.Right},
];

export function FormatControls(props: FormatControlsProps) {
const action = (actionName: string, args?: any) => props.onAction({actionName, args});

Expand All @@ -30,22 +36,22 @@ export function FormatControls(props: FormatControlsProps) {
})),
),
React.createElement('div', {className: 'ows-button-row'},
React.createElement(AlignButton, {action, alignment: TextAlign.Left, appearance: props.appearance}),
React.createElement(AlignButton, {action, alignment: TextAlign.Center, appearance: props.appearance}),
React.createElement(AlignButton, {action, alignment: TextAlign.Right, appearance: props.appearance}),
alignments.map((alignment) => React.createElement(AlignButton, {
action,
alignment,
appearance: props.appearance,
key: alignment.value,
})),
),
),
);
}

function AlignButton({action, alignment, appearance}: any) {
const icon = alignment === TextAlign.Left
? 'fa fa-align-left'
: alignment === TextAlign.Center ? 'fa fa-align-center' : 'fa fa-align-right';

return React.createElement(Button, {
active: appearance.textAlign === alignment,
icon,
onClick: () => action('align', alignment),
active: appearance.textAlign === alignment.textAlign,
icon: alignment.icon,
onClick: () => action('align', alignment.value),
title: alignment.label,
});
}
10 changes: 10 additions & 0 deletions src/features/ribbon/RibbonMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('RibbonMenu', () => {
expect(onAction).toHaveBeenCalledWith({actionName: 'outside-border', args: '#000000'});
});

it('emits text alignment command values the core accepts', () => {
const onAction = renderRibbon();

fireEvent.click(screen.getByTitle('Align center'));
fireEvent.click(screen.getByTitle('Align right'));

expect(onAction).toHaveBeenCalledWith({actionName: 'align', args: 'center'});
expect(onAction).toHaveBeenCalledWith({actionName: 'align', args: 'right'});
});

it('toggles view layout section items', async () => {
renderRibbon();

Expand Down