Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
/**
* Copyright 2023-present DreamNum Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LocaleService } from '@univerjs/core';
import { Button, Input, MobileActionRowGroup, MobileSelect } from '@univerjs/design';
import { getDateFormatOptions } from '@univerjs/sheets-numfmt';
import { useDependency, useObservable } from '@univerjs/ui';
import { useMemo, useState } from 'react';
import type { LocaleKey } from '../../locale/types';
export interface IMobileCustomFormatProps {
patterns: string[];
onConfirm: (pattern: string) => void;
}
export function MobileCustomFormat(props: IMobileCustomFormatProps) {
const { patterns, onConfirm } = props;
const localeService = useDependency(LocaleService);
const locale = useObservable(localeService.currentLocale$, localeService.getCurrentLocale());
const [pattern, setPattern] = useState('');
const title = localeService.t<LocaleKey>('sheets-numfmt-ui.customFormat');
// Menu configuration outlives locale changes; resolve date presets when the editor renders.
const options = useMemo(() => [...new Set([
...patterns,
...getDateFormatOptions(locale).map((item) => item.value),
...(pattern ? [pattern] : []),
])].map((value) => ({ label: value, value })), [locale, pattern, patterns]);
return (
<div
data-u-comp="mobile-custom-format"
className="univer-flex univer-h-full univer-min-h-0 univer-flex-col univer-gap-4"
>
<Input
className="univer-shrink-0"
aria-label={title}
value={pattern}
placeholder={title}
onChange={setPattern}
size="small"
/>
<MobileSelect
className="
univer-w-full univer-shrink-0
[&>div]:univer-font-mono
"
value={pattern || title}
options={options}
onChange={setPattern}
size="small"
/>
<div
className="
univer-flex-1 univer-px-1 univer-text-sm univer-text-gray-600
dark:!univer-text-gray-200
"
>
{localeService.t<LocaleKey>('sheets-numfmt-ui.customFormatDes')}
</div>
<MobileActionRowGroup className="univer-shrink-0">
<Button variant="primary" disabled={!pattern.trim()} onClick={() => onConfirm(pattern.trim())} size="middle">
{localeService.t<LocaleKey>('sheets-numfmt-ui.confirm')}
</Button>
</MobileActionRowGroup>
</div>
);
}