文件
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

69 行
1.9 KiB
TypeScript

import * as React from 'react';
import { useCallback } from 'react';
import CommandService from '@joplin/lib/services/CommandService';
import { _ } from '@joplin/lib/locale';
import StyledInput from '../../style/StyledInput';
interface Props {
inputRef?: React.Ref<HTMLInputElement>;
value: string;
onChange(event: OnChangeEvent): void;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
onSearchButtonClick: ()=> void;
searchStarted: boolean;
placeholder?: string;
disabled?: boolean;
inputClassName?: string;
'aria-controls'?: string;
iconButtonTabIndex?: number;
}
export interface OnChangeEvent {
value: string;
}
export default function(props: Props) {
const iconName = !props.searchStarted ? CommandService.instance().iconName('search') : 'fa fa-times';
const iconLabel = !props.searchStarted ? _('Search') : _('Clear search');
const onChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
props.onChange({ value: event.currentTarget.value });
}, [props.onChange]);
const fieldClassName = ['field'];
if (props.inputClassName) fieldClassName.push(props.inputClassName);
return (
<div className='search-input'>
<StyledInput
ref={props.inputRef}
className={fieldClassName.join(' ')}
value={props.value}
type="search"
placeholder={props.placeholder || _('Search...')}
onChange={onChange}
onFocus={props.onFocus}
onBlur={props.onBlur}
onKeyDown={props.onKeyDown}
spellCheck={false}
disabled={props.disabled}
aria-label={props.placeholder || _('Search...')}
aria-controls={props['aria-controls']}
/>
<button
type='button'
className='button'
aria-label={iconLabel}
disabled={props.disabled}
tabIndex={props.iconButtonTabIndex}
onClick={props.onSearchButtonClick}
>
<span className={`icon ${iconName}`}/>
</button>
</div>
);
}