Skip to content

Commit 952774f

Browse files
authored
fix: send text alignment command values (#66)
Co-authored-by: Sia <me@siamand.cc>
1 parent 69c1a24 commit 952774f

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
crossorigin="anonymous">
1111
<link rel="icon" href="/OpenWebSheet/favicon.ico">
1212
<title>Open web sheet</title>
13-
<script type="module" crossorigin src="/OpenWebSheet/assets/index-BChN-qVl.js"></script>
13+
<script type="module" crossorigin src="/OpenWebSheet/assets/index-DrD1_fGU.js"></script>
1414
<link rel="stylesheet" crossorigin href="/OpenWebSheet/assets/index-Cs_txOUy.css">
1515
</head>
1616
<body>

src/features/ribbon/FormatControls.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ interface FormatControlsProps {
1010
onAction: (action: AppAction) => void;
1111
}
1212

13+
const alignments = [
14+
{icon: 'fa fa-align-left', label: 'Align left', value: 'left', textAlign: TextAlign.Left},
15+
{icon: 'fa fa-align-center', label: 'Align center', value: 'center', textAlign: TextAlign.Center},
16+
{icon: 'fa fa-align-right', label: 'Align right', value: 'right', textAlign: TextAlign.Right},
17+
];
18+
1319
export function FormatControls(props: FormatControlsProps) {
1420
const action = (actionName: string, args?: any) => props.onAction({actionName, args});
1521

@@ -30,22 +36,22 @@ export function FormatControls(props: FormatControlsProps) {
3036
})),
3137
),
3238
React.createElement('div', {className: 'ows-button-row'},
33-
React.createElement(AlignButton, {action, alignment: TextAlign.Left, appearance: props.appearance}),
34-
React.createElement(AlignButton, {action, alignment: TextAlign.Center, appearance: props.appearance}),
35-
React.createElement(AlignButton, {action, alignment: TextAlign.Right, appearance: props.appearance}),
39+
alignments.map((alignment) => React.createElement(AlignButton, {
40+
action,
41+
alignment,
42+
appearance: props.appearance,
43+
key: alignment.value,
44+
})),
3645
),
3746
),
3847
);
3948
}
4049

4150
function AlignButton({action, alignment, appearance}: any) {
42-
const icon = alignment === TextAlign.Left
43-
? 'fa fa-align-left'
44-
: alignment === TextAlign.Center ? 'fa fa-align-center' : 'fa fa-align-right';
45-
4651
return React.createElement(Button, {
47-
active: appearance.textAlign === alignment,
48-
icon,
49-
onClick: () => action('align', alignment),
52+
active: appearance.textAlign === alignment.textAlign,
53+
icon: alignment.icon,
54+
onClick: () => action('align', alignment.value),
55+
title: alignment.label,
5056
});
5157
}

src/features/ribbon/RibbonMenu.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ describe('RibbonMenu', () => {
5454
expect(onAction).toHaveBeenCalledWith({actionName: 'outside-border', args: '#000000'});
5555
});
5656

57+
it('emits text alignment command values the core accepts', () => {
58+
const onAction = renderRibbon();
59+
60+
fireEvent.click(screen.getByTitle('Align center'));
61+
fireEvent.click(screen.getByTitle('Align right'));
62+
63+
expect(onAction).toHaveBeenCalledWith({actionName: 'align', args: 'center'});
64+
expect(onAction).toHaveBeenCalledWith({actionName: 'align', args: 'right'});
65+
});
66+
5767
it('toggles view layout section items', async () => {
5868
renderRibbon();
5969

0 commit comments

Comments
 (0)