Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 0b46cbc

Browse files
committed
first version text align selector working
1 parent 2e76c0b commit 0b46cbc

File tree

8 files changed

+54
-16
lines changed

8 files changed

+54
-16
lines changed

src/components/cellTypes/FormulaCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const FormulaCell = (mdProps: CellComponentProps) => {
4646
return (
4747
<span
4848
ref={formulaRef}
49-
className={`${c("md_cell")}`}
49+
className={`${c("md_cell " + tableColumn.config.content_alignment)}`}
5050
key={`formula_${cell.id}`}
5151
/>
5252
);

src/components/cellTypes/NumberCell.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CellComponentProps } from "cdm/ComponentsModel";
22
import { TableColumn } from "cdm/FolderModel";
3+
import { c } from "helpers/StylesHelper";
34
import React, {
45
ChangeEventHandler,
56
KeyboardEventHandler,
@@ -15,7 +16,7 @@ const NumberCell = (props: CellComponentProps) => {
1516
const dataActions = tableState.data((state) => state.actions);
1617
const numberRow = tableState.data((state) => state.rows[row.index]);
1718
const configInfo = tableState.configState((state) => state.info);
18-
19+
const tableColumn = column.columnDef as TableColumn;
1920
const [editableValue, setEditableValue] = useState(null);
2021
const [dirtyCell, setDirtyCell] = useState(false);
2122

@@ -34,7 +35,7 @@ const NumberCell = (props: CellComponentProps) => {
3435
function persistChange(changedValue: number) {
3536
dataActions.updateCell(
3637
row.index,
37-
column.columnDef as TableColumn,
38+
tableColumn,
3839
changedValue,
3940
columnsInfo.getAllColumns(),
4041
configInfo.getLocalSettings()
@@ -60,11 +61,11 @@ const NumberCell = (props: CellComponentProps) => {
6061
onChange={handleOnChange}
6162
onKeyDown={handleKeyDown}
6263
onBlur={handleOnBlur}
63-
className="text-align-right"
64+
className={c(tableColumn.config.content_alignment)}
6465
/>
6566
) : (
6667
<span
67-
className="text-align-right"
68+
className={c(tableColumn.config.content_alignment)}
6869
onClick={handleEditableOnclick}
6970
style={{ width: column.getSize() }}
7071
>

src/components/cellTypes/TextCell.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import React, { MouseEventHandler, useEffect, useRef } from "react";
44
import { useState } from "react";
55
import EditorCell from "components/cellTypes/EditorCell";
66
import { TableColumn } from "cdm/FolderModel";
7+
import { c } from "helpers/StylesHelper";
78

89
const TextCell = (props: CellComponentProps) => {
910
const { defaultCell } = props;
1011
const { cell, column, table, row } = defaultCell;
1112
const { tableState } = table.options.meta;
12-
13+
const tableColumn = column.columnDef as TableColumn;
1314
const textRow = tableState.data((state) => state.rows[row.index]);
1415

1516
const configInfo = table.options.meta.tableState.configState(
@@ -52,7 +53,7 @@ const TextCell = (props: CellComponentProps) => {
5253
if (changedValue !== undefined && changedValue !== textCell) {
5354
dataActions.updateCell(
5455
row.index,
55-
column.columnDef as TableColumn,
56+
tableColumn,
5657
changedValue.trim(),
5758
columnsInfo.getAllColumns(),
5859
configInfo.getLocalSettings()
@@ -72,6 +73,7 @@ const TextCell = (props: CellComponentProps) => {
7273
ref={containerCellRef}
7374
onClick={handleEditableOnclick}
7475
style={{ width: column.getSize() }}
76+
className={c(tableColumn.config.content_alignment)}
7577
/>
7678
);
7779
};

src/components/modals/columnSettings/ColumnSections.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ import { InputType } from "helpers/Constants";
1212
import { AbstractChain } from "patterns/AbstractFactoryChain";
1313
import { AbstractHandler } from "patterns/AbstractHandler";
1414

15+
class StyleSetttingsSection extends AbstractChain<ColumnSettingsHandlerResponse> {
16+
private input: string = InputType.TEXT;
17+
protected runBefore(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
18+
this.input = columnHandlerResponse.column.input;
19+
return columnHandlerResponse;
20+
}
21+
protected customHandle(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
22+
const style_section = columnHandlerResponse.containerEl.createDiv("column-section-container-style");
23+
add_setting_header(style_section, "Style", "h3");
24+
columnHandlerResponse.containerEl = style_section;
25+
return columnHandlerResponse;
26+
}
27+
protected getHandlers(): AbstractHandler<ColumnSettingsHandlerResponse>[] {
28+
const particularHandlers: AbstractHandler<ColumnSettingsHandlerResponse>[] = [];
29+
switch (this.input) {
30+
case InputType.TEXT:
31+
case InputType.NUMBER:
32+
case InputType.FORMULA:
33+
particularHandlers.push(new AlignmentSelectorHandler());
34+
break;
35+
default:
36+
// do nothing
37+
}
38+
return particularHandlers;
39+
}
40+
}
41+
export const style_settings_section = new StyleSetttingsSection();
42+
1543
class BehaviorSetttingsSection extends AbstractChain<ColumnSettingsHandlerResponse> {
1644
private input: string = InputType.TEXT;
1745
protected runBefore(columnHandlerResponse: ColumnSettingsHandlerResponse): ColumnSettingsHandlerResponse {
@@ -26,7 +54,6 @@ class BehaviorSetttingsSection extends AbstractChain<ColumnSettingsHandlerRespon
2654
}
2755
protected getHandlers(): AbstractHandler<ColumnSettingsHandlerResponse>[] {
2856
const particularHandlers: AbstractHandler<ColumnSettingsHandlerResponse>[] = [];
29-
particularHandlers.push(new AlignmentSelectorHandler());
3057
switch (this.input) {
3158
case InputType.TASK:
3259
// do nothing

src/components/modals/columnSettings/ColumnSettingsModal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Modal } from "obsidian";
44
import { add_setting_header } from "settings/SettingsComponents";
55
import { StyleClasses } from "helpers/Constants";
66
import { ColumnSettingsHandlerResponse, ColumnSettingsModalProps } from "cdm/ModalsModel";
7-
import { particular_settings_section, behavior_settings_section } from "components/modals/columnSettings/ColumnSections";
7+
import { particular_settings_section, behavior_settings_section, style_settings_section } from "components/modals/columnSettings/ColumnSections";
88
import { HeaderMenuProps } from "cdm/HeaderModel";
99
import { ColumnsState, ConfigState, DataState } from "cdm/TableStateInterface";
1010

@@ -70,6 +70,8 @@ export class ColumnSettingsManager {
7070
constructBody(response: ColumnSettingsHandlerResponse) {
7171
/** behavior section */
7272
behavior_settings_section.run(response);
73+
/** styles section */
74+
style_settings_section.run(response);
7375
/** Particular settings section */
7476
particular_settings_section.run(response);
7577
}

src/helpers/Constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export const MetadataLabels = Object.freeze({
7575
* COLUMN CONFIGURATIONS *
7676
******************************************************************************/
7777
export const COLUMN_ALIGNMENT_OPTIONS = Object.freeze({
78-
LEFT: 'left',
79-
CENTER: 'center',
80-
RIGHT: 'right',
78+
LEFT: 'text-align-left',
79+
CENTER: 'text-align-center',
80+
RIGHT: 'text-align-right',
8181
});
8282

8383
export const DEFAULT_COLUMN_CONFIG: ConfigColumn = Object.freeze({

src/helpers/StylesHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DatabaseCore, MetadataLabels } from "helpers/Constants";
1+
import { COLUMN_ALIGNMENT_OPTIONS, DatabaseCore, MetadataLabels } from "helpers/Constants";
22

33
/**
44
* Wrap the classname of css elements
@@ -39,4 +39,4 @@ export function getLabelHeader(input: string) {
3939
}
4040
});
4141
return labelCandidate === undefined ? input : labelCandidate[1];
42-
}
42+
}

styles.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,18 @@ div.database-plugin__checkbox {
489489
gap: 0.3rem;
490490
}
491491

492-
span.text-align-right {
492+
.database-plugin__text-align-right {
493493
display: flex;
494-
align-items: center;
494+
align-items: right;
495495
justify-content: flex-end;
496496
}
497497

498+
.database-plugin__text-align-center {
499+
display: flex;
500+
align-items: center;
501+
justify-content: center;
502+
}
503+
498504
.database-plugin__text-align-left {
499505
display: flex;
500506
text-align: left;

0 commit comments

Comments
 (0)