Skip to content

Commit f763b08

Browse files
committed
refactor: create generic list styles button
1 parent 6c06579 commit f763b08

4 files changed

Lines changed: 45 additions & 158 deletions

File tree

packages/super-editor/src/editors/v1/components/toolbar/NumberedStyleButtons.vue

Lines changed: 0 additions & 141 deletions
This file was deleted.

packages/super-editor/src/editors/v1/components/toolbar/BulletStyleButtons.vue renamed to packages/super-editor/src/editors/v1/components/toolbar/StyleButtonsList.vue

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
<script setup>
2-
import { onMounted, ref } from 'vue';
2+
import { computed, onMounted, ref } from 'vue';
33
import { useHighContrastMode } from '../../composables/use-high-contrast-mode';
4-
import { toolbarIcons } from './toolbarIcons.js';
54
65
const { isHighContrastMode } = useHighContrastMode();
76
const emit = defineEmits(['select']);
87
98
const props = defineProps({
9+
buttons: {
10+
type: Array,
11+
required: true,
12+
},
1013
selectedStyle: {
1114
type: String,
1215
default: null,
1316
},
17+
iconSize: {
18+
type: Number,
19+
default: 25,
20+
},
1421
});
1522
1623
const buttonRefs = ref([]);
17-
const bulletButtons = [
18-
{ key: 'disc', icon: toolbarIcons.bulletListDisc, ariaLabel: 'Opaque circle' },
19-
{ key: 'circle', icon: toolbarIcons.bulletListCircle, ariaLabel: 'Outline circle' },
20-
{ key: 'square', icon: toolbarIcons.bulletListSquare, ariaLabel: 'Opaque square' },
21-
];
24+
25+
const iconStyle = computed(() => ({
26+
width: `${props.iconSize}px`,
27+
height: `${props.iconSize}px`,
28+
}));
2229
2330
const select = (key) => {
2431
emit('select', key);
@@ -51,7 +58,7 @@ const handleKeyDown = (e, index) => {
5158
moveToNextButton(index);
5259
break;
5360
case 'Enter':
54-
select(bulletButtons[index].key);
61+
select(props.buttons[index].key);
5562
break;
5663
default:
5764
break;
@@ -68,12 +75,13 @@ onMounted(() => {
6875
</script>
6976

7077
<template>
71-
<div class="bullet-style-buttons" :class="{ 'high-contrast': isHighContrastMode }">
78+
<div class="style-buttons-list" :class="{ 'high-contrast': isHighContrastMode }">
7279
<div
73-
v-for="(button, index) in bulletButtons"
80+
v-for="(button, index) in props.buttons"
7481
:key="button.key"
7582
class="button-icon"
7683
:class="{ selected: props.selectedStyle === button.key }"
84+
:style="iconStyle"
7785
@click="select(button.key)"
7886
v-html="button.icon"
7987
role="menuitem"
@@ -85,7 +93,7 @@ onMounted(() => {
8593
</template>
8694

8795
<style scoped>
88-
.bullet-style-buttons {
96+
.style-buttons-list {
8997
display: flex;
9098
justify-content: space-between;
9199
width: 100%;
@@ -97,8 +105,6 @@ onMounted(() => {
97105
padding: 5px;
98106
font-size: var(--sd-ui-font-size-600, 16px);
99107
color: var(--sd-ui-dropdown-text, #47484a);
100-
width: 25px;
101-
height: 25px;
102108
border-radius: var(--sd-ui-dropdown-option-radius, 3px);
103109
display: flex;
104110
justify-content: center;

packages/super-editor/src/editors/v1/components/toolbar/defaultItems.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { normalizeFontOption } from './helpers/font-options.js';
55
import { useToolbarItem } from './use-toolbar-item';
66
import AIWriter from './AIWriter.vue';
77
import AlignmentButtons from './AlignmentButtons.vue';
8-
import BulletStyleButtons from './BulletStyleButtons.vue';
9-
import NumberedStyleButtons from './NumberedStyleButtons.vue';
8+
import StyleButtonsList from './StyleButtonsList.vue';
9+
import { bulletStyleButtons, numberedStyleButtons } from './list-style-buttons.js';
1010
import DocumentMode from './DocumentMode.vue';
1111
import LinkedStyle from './LinkedStyle.vue';
1212
import LinkInput from './LinkInput.vue';
@@ -655,7 +655,9 @@ export const makeDefaultItems = ({
655655
const item = { ...bulletedList, command: 'toggleBulletListStyle' };
656656
superToolbar.emitCommand({ item, argument: style });
657657
};
658-
return h(BulletStyleButtons, {
658+
return h(StyleButtonsList, {
659+
buttons: bulletStyleButtons,
660+
iconSize: 25,
659661
selectedStyle: bulletedList.selectedValue.value,
660662
onSelect: handleSelect,
661663
});
@@ -688,7 +690,9 @@ export const makeDefaultItems = ({
688690
const item = { ...numberedList, command: 'toggleOrderedListStyle' };
689691
superToolbar.emitCommand({ item, argument: style });
690692
};
691-
return h(NumberedStyleButtons, {
693+
return h(StyleButtonsList, {
694+
buttons: numberedStyleButtons,
695+
iconSize: 30,
692696
selectedStyle: numberedList.selectedValue.value,
693697
onSelect: handleSelect,
694698
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { toolbarIcons } from './toolbarIcons.js';
2+
3+
export const bulletStyleButtons = [
4+
{ key: 'disc', icon: toolbarIcons.bulletListDisc, ariaLabel: 'Opaque circle' },
5+
{ key: 'circle', icon: toolbarIcons.bulletListCircle, ariaLabel: 'Outline circle' },
6+
{ key: 'square', icon: toolbarIcons.bulletListSquare, ariaLabel: 'Opaque square' },
7+
];
8+
9+
export const numberedStyleButtons = [
10+
{ key: 'decimal', icon: toolbarIcons.numberedListDecimal, ariaLabel: '1. 2. 3.' },
11+
{ key: 'decimal-paren', icon: toolbarIcons.numberedListDecimalParen, ariaLabel: '1) 2) 3)' },
12+
{ key: 'upper-roman', icon: toolbarIcons.numberedListUpperRoman, ariaLabel: 'I. II. III.' },
13+
{ key: 'lower-roman', icon: toolbarIcons.numberedListLowerRoman, ariaLabel: 'i. ii. iii.' },
14+
{ key: 'upper-alpha', icon: toolbarIcons.numberedListUpperAlpha, ariaLabel: 'A. B. C.' },
15+
{ key: 'upper-alpha-paren', icon: toolbarIcons.numberedListUpperAlphaParen, ariaLabel: 'A) B) C)' },
16+
{ key: 'lower-alpha', icon: toolbarIcons.numberedListLowerAlpha, ariaLabel: 'a. b. c.' },
17+
{ key: 'lower-alpha-paren', icon: toolbarIcons.numberedListLowerAlphaParen, ariaLabel: 'a) b) c)' },
18+
];

0 commit comments

Comments
 (0)