From 9674b45cf0bd0e3556854d0bddc955fda485f170 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Thu, 22 May 2025 13:03:10 +0800 Subject: [PATCH] layout: align text end for select labels on safari (#1219) --- .../components/annotator/TranslatorPopup.tsx | 69 +++++++------------ apps/readest-app/src/components/Select.tsx | 37 ++++++++++ 2 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 apps/readest-app/src/components/Select.tsx diff --git a/apps/readest-app/src/app/reader/components/annotator/TranslatorPopup.tsx b/apps/readest-app/src/app/reader/components/annotator/TranslatorPopup.tsx index c8ac049b..866bd49e 100644 --- a/apps/readest-app/src/app/reader/components/annotator/TranslatorPopup.tsx +++ b/apps/readest-app/src/app/reader/components/annotator/TranslatorPopup.tsx @@ -1,4 +1,3 @@ -import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; import Popup from '@/components/Popup'; import { Position } from '@/utils/sel'; @@ -8,6 +7,7 @@ import { useTranslation } from '@/hooks/useTranslation'; import { useTranslator } from '@/hooks/useTranslator'; import { TRANSLATED_LANGS } from '@/services/constants'; import { TranslatorName } from '@/services/translators'; +import Select from '@/components/Select'; const notSupportedLangs = ['hi', 'vi']; @@ -147,28 +147,23 @@ const TranslatorPopup: React.FC = ({

{_('Original Text')}

- + options={[ + { value: 'AUTO', label: _('Auto Detect') }, + ...Object.entries(TRANSLATOR_LANGS) + .sort((a, b) => a[1].localeCompare(b[1])) + .map(([code, name]) => { + const label = + detectedSourceLang && sourceLang === 'AUTO' && code === 'AUTO' + ? `${TRANSLATOR_LANGS[detectedSourceLang] || detectedSourceLang} ` + + _('(detected)') + : name; + return { value: code, label }; + }), + ]} + />

{text}

@@ -178,22 +173,13 @@ const TranslatorPopup: React.FC = ({

{_('Translated Text')}

- + .map(([code, name]) => ({ value: code, label: name }))} + />
{loading ? ( @@ -217,20 +203,11 @@ const TranslatorPopup: React.FC = ({ })}
)} - + options={providers.map(({ name: value, label }) => ({ value, label }))} + /> )} diff --git a/apps/readest-app/src/components/Select.tsx b/apps/readest-app/src/components/Select.tsx new file mode 100644 index 00000000..76583669 --- /dev/null +++ b/apps/readest-app/src/components/Select.tsx @@ -0,0 +1,37 @@ +import clsx from 'clsx'; +import React from 'react'; + +type Option = { + value: string; + label: string; +}; + +type SelectProps = { + value: string; + onChange: (e: React.ChangeEvent) => void; + options: Option[]; + className?: string; +}; + +export default function Select({ value, onChange, options, className }: SelectProps) { + return ( + + ); +}