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

Commit bc13f56

Browse files
committed
Merge branch 'input-styling'
2 parents 4386cea + 7d1bac9 commit bc13f56

File tree

12 files changed

+287
-12
lines changed

12 files changed

+287
-12
lines changed

src/components/HeaderMenu.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { HeaderMenuProps } from "cdm/HeaderModel";
1313
import Box from "@mui/material/Box";
1414
import ClickAwayListener from "@mui/material/ClickAwayListener";
1515
import { Platform } from "obsidian";
16+
import { dynamic_t, t } from "lang/helpers";
1617

1718
const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
1819
const { table, column } = headerMenuProps.headerProps;
@@ -156,7 +157,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
156157
color: StyleVariables.TEXT_FAINT,
157158
}}
158159
>
159-
Property Type
160+
{t("header_menu_property_type")}
160161
</span>
161162
</div>
162163
{/** Type of column section */}
@@ -179,7 +180,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
179180
{propertyIcon}
180181
</span>
181182
<span style={{ textTransform: "capitalize" }}>
182-
{getLabelHeader(input)}
183+
{dynamic_t(input)}
183184
</span>
184185
</div>
185186
<Popper
@@ -246,7 +247,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
246247
<span className="svg-icon svg-text icon-margin">
247248
<AdjustmentsIcon />
248249
</span>
249-
<span>Settings</span>
250+
<span>{t("header_menu_settings")}</span>
250251
</div>
251252
</div>
252253
</div>

src/components/cellTypes/CalendarCell.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ParseService } from "services/ParseService";
1414
import { DEFAULT_SETTINGS, InputType } from "helpers/Constants";
1515
import { Platform } from "obsidian";
1616
import { parseLuxonDateToString } from "helpers/LuxonHelper";
17+
import { OBSIDIAN_LOCALE } from "lang/helpers";
1718

1819
const CalendarCell = (calendarProps: CellComponentProps) => {
1920
const { defaultCell } = calendarProps;
@@ -95,6 +96,8 @@ const CalendarCell = (calendarProps: CellComponentProps) => {
9596
isClearable
9697
ariaLabelClose="Clear"
9798
placeholderText="Pick a date..."
99+
locale={OBSIDIAN_LOCALE}
100+
calendarStartDay={1}
98101
/>
99102
) : (
100103
<span

src/components/cellTypes/CalendarTimeCell.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DEFAULT_SETTINGS, InputType } from "helpers/Constants";
1414
import { c } from "helpers/StylesHelper";
1515
import { Platform } from "obsidian";
1616
import { parseLuxonDatetimeToString } from "helpers/LuxonHelper";
17+
import { OBSIDIAN_LOCALE } from "lang/helpers";
1718

1819
const CalendarTimeCell = (calendarTimeProps: CellComponentProps) => {
1920
const { defaultCell } = calendarTimeProps;
@@ -96,6 +97,8 @@ const CalendarTimeCell = (calendarTimeProps: CellComponentProps) => {
9697
isClearable
9798
ariaLabelClose="Clear"
9899
placeholderText="Pick a moment..."
100+
locale={OBSIDIAN_LOCALE}
101+
calendarStartDay={1}
99102
/>
100103
) : (
101104
<span

src/components/cellTypes/EditorCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { ChangeEventHandler, useCallback, useRef } from "react";
44
import { useState } from "react";
55
import { MarkdownEditor } from "components/cellTypes/Editor/MarkdownEditor";
66
import { c } from "helpers/StylesHelper";
7+
import useAutosizeTextArea from "components/styles/hooks/useAutosizeTextArea";
78

89
const EditorCell = (props: EditorCellComponentProps) => {
910
const { defaultCell, persistChange, textCell } = props;
@@ -35,7 +36,6 @@ const EditorCell = (props: EditorCellComponentProps) => {
3536
editableMdRef.current.blur();
3637
}
3738
};
38-
3939
/**
4040
* Close editor undoing any changes realised
4141
*/
@@ -50,6 +50,7 @@ const EditorCell = (props: EditorCellComponentProps) => {
5050
persistChange(editorValue?.toString());
5151
};
5252

53+
useAutosizeTextArea(editableMdRef.current, editorValue);
5354
return (
5455
<>
5556
<MarkdownEditor

src/components/contextMenu/CellContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function CellContextMenu(
3636
);
3737
};
3838

39-
const index = Number(row.index) + 1;
39+
const index = Number(table.getRowModel().flatRows.indexOf(row)) + 1;
4040

4141
return (
4242
<>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useEffect } from "react";
2+
3+
/**
4+
* Updates the height of a <textarea> when the value changes.
5+
* @param textAreaRef
6+
* @param value
7+
*/
8+
const useAutosizeTextArea = (
9+
textAreaRef: HTMLTextAreaElement | null,
10+
value: string
11+
) => {
12+
useEffect(() => {
13+
if (textAreaRef) {
14+
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
15+
textAreaRef.style.height = "0px";
16+
const scrollHeight = textAreaRef.scrollHeight;
17+
18+
// We then set the height directly, outside of the render loop
19+
// Trying to set this with state or a ref will product an incorrect value.
20+
textAreaRef.style.height = scrollHeight + "px";
21+
}
22+
}, [textAreaRef, value]);
23+
};
24+
25+
export default useAutosizeTextArea;

src/lang/helpers.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import tr from 'lang/locale/tr';
2222
import uk from 'lang/locale/tr';
2323
import zhCN from 'lang/locale/zh-cn';
2424
import zhTW from 'lang/locale/zh-tw';
25+
26+
import * as Locales from 'date-fns/locale';
27+
2528
import { LOGGER } from 'services/Logger';
29+
import { registerLocale } from 'react-datepicker';
2630

2731
const localeMap: { [k: string]: Partial<typeof en> } = {
2832
ar,
@@ -51,8 +55,8 @@ const localeMap: { [k: string]: Partial<typeof en> } = {
5155
zh: zhCN,
5256
};
5357

54-
const lang = localStorage.getItem('language');
55-
const locale = localeMap[lang || 'en'];
58+
export const OBSIDIAN_LOCALE = localStorage.getItem('language');
59+
const locale = localeMap[OBSIDIAN_LOCALE || 'en'];
5660

5761
/**
5862
* Translate a string to the current language or English if not found.
@@ -64,7 +68,7 @@ const locale = localeMap[lang || 'en'];
6468
*/
6569
export function t(str: keyof typeof en, ...args: string[]): string {
6670
if (!locale) {
67-
LOGGER.error('Error: database locale not found', lang);
71+
LOGGER.error('Error: database locale not found', OBSIDIAN_LOCALE);
6872
}
6973
const translated = (locale && locale[str]) || en[str];
7074

@@ -76,3 +80,25 @@ export function t(str: keyof typeof en, ...args: string[]): string {
7680
// Replace any arguments in the string
7781
return args.reduce((acc, arg, i) => acc.replace(`{${i}}`, arg), translated);
7882
}
83+
84+
/**
85+
* If you trust the string to be in the current language (e.g. variable names) then use this.
86+
* @param str
87+
* @param args
88+
* @returns
89+
*/
90+
export function dynamic_t(str: string, ...args: string[]): string {
91+
return t(str as keyof typeof en, ...args);
92+
}
93+
94+
/**
95+
* Looks up a date-fns locale from the Expo localization object. This falls back to `en-US`
96+
* @param localization Expo Localization object containing the locale and region.
97+
* @returns date-fns locale.
98+
*/
99+
export function registerDateFnLocale() {
100+
const dynamicLocale =
101+
Locales[OBSIDIAN_LOCALE as keyof typeof Locales] || Locales.enUS;
102+
103+
registerLocale(OBSIDIAN_LOCALE, dynamicLocale);
104+
}

src/lang/locale/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export default {
6060
"header_menu_hide_column": "Hide",
6161
"header_menu_insert_column_left": "Insert left",
6262
"header_menu_insert_column_right": "Insert right",
63+
"header_menu_settings": "Settings",
64+
"header_menu_property_type": "Property Type",
6365
/** INPUT LABELS */
6466
"number": "Number",
6567
"text": "Text",

0 commit comments

Comments
 (0)