Skip to content

Commit d943ddc

Browse files
committed
Tweaks
1 parent ec84a21 commit d943ddc

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

packages/gitbook/src/components/DocumentView/Integration/contentkit.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@
156156

157157
/** Text input */
158158
.contentkit-textinput {
159-
@apply w-full rounded border border-tint text-tint-strong placeholder:text-tint flex resize-none flex-1 px-2 py-1.5 text-sm bg-transparent whitespace-pre-line;
160-
@apply focus:outline-primary focus:border-primary;
159+
@apply w-full circular-corners:rounded-3xl ring-primary-hover rounded-corners:rounded-lg border border-tint text-tint-strong transition-all placeholder:text-tint/8 flex resize-none flex-1 px-2 py-1.5 text-sm bg-tint-base whitespace-pre-line;
160+
@apply shadow-tint/6 depth-subtle:focus-within:-translate-y-px depth-subtle:shadow-sm depth-subtle:focus-within:shadow-lg dark:shadow-tint-1;
161+
@apply focus:border-primary-hover focus:shadow-primary-subtle focus:ring-2 hover:border-tint-hover focus:hover:border-primary-hover;
162+
@apply disabled:cursor-not-allowed disabled:border-tint-subtle disabled:bg-tint-subtle;
161163
}
162164

163165
/** Form */

packages/gitbook/src/components/PageFeedback/PageFeedbackForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { useLanguage } from '@/intl/client';
77
import { t, tString } from '@/intl/translate';
88
import { tcls } from '@/lib/tailwind';
99
import { useTrackEvent } from '../Insights';
10-
import { Button, ButtonGroup } from '../primitives';
11-
import { Input } from '../primitives/Input';
10+
import { Button, ButtonGroup, Input } from '../primitives';
1211

1312
const MIN_COMMENT_LENGTH = 3;
1413
const MAX_COMMENT_LENGTH = 512;

packages/gitbook/src/components/Search/SearchInput.tsx

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { useEffect, useRef } from 'react';
33

44
import { tString, useLanguage } from '@/intl/client';
5-
import { Input } from '../primitives/Input';
5+
import { Input } from '../primitives';
66
import { KeyboardShortcut } from '../primitives/KeyboardShortcut';
77

88
interface SearchInputProps {
@@ -50,32 +50,34 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
5050
}, [isOpen, value]);
5151

5252
return (
53-
<Input
54-
data-testid="search-input"
55-
name="search-input"
56-
ref={inputRef}
57-
containerRef={containerRef as React.RefObject<HTMLDivElement | null>}
58-
sizing="small"
59-
label={tString(language, withAI ? 'search_or_ask' : 'search')}
60-
className="grow"
61-
placeholder={`${tString(language, withAI ? 'search_or_ask' : 'search')}…`}
62-
onFocus={onFocus}
63-
onKeyDown={onKeyDown}
64-
leading="magnifying-glass"
65-
onChange={(event) => {
66-
onChange(event.target.value);
67-
}}
68-
value={value}
69-
maxLength={512}
70-
autoComplete="off"
71-
aria-autocomplete="list"
72-
aria-haspopup="listbox"
73-
aria-expanded={value && isOpen ? 'true' : 'false'}
74-
clearButton
75-
keyboardShortcut={<KeyboardShortcut keys={isOpen ? ['esc'] : ['mod', 'k']} />}
76-
{...rest}
77-
type="text"
78-
/>
53+
<div className="relative flex @max-2xl:size-10 grow">
54+
<Input
55+
data-testid="search-input"
56+
name="search-input"
57+
ref={inputRef}
58+
containerRef={containerRef as React.RefObject<HTMLDivElement | null>}
59+
sizing="small"
60+
label={tString(language, withAI ? 'search_or_ask' : 'search')}
61+
className="@max-2xl:absolute inset-y-0 right-0 z-30 @max-2xl:max-w-10 grow @max-2xl:focus-within:w-56 @max-2xl:focus-within:max-w-[calc(100vw-5rem)] @max-2xl:has-[input[aria-expanded=true]]:w-56 @max-2xl:has-[input[aria-expanded=true]]:max-w-[calc(100vw-5rem)] @max-2xl:[&_input]:opacity-0 @max-2xl:focus-within:[&_input]:opacity-11 @max-2xl:has-[input[aria-expanded=true]]:[&_input]:opacity-11"
62+
placeholder={`${tString(language, withAI ? 'search_or_ask' : 'search')}…`}
63+
onFocus={onFocus}
64+
onKeyDown={onKeyDown}
65+
leading="magnifying-glass"
66+
onChange={(event) => {
67+
onChange(event.target.value);
68+
}}
69+
value={value}
70+
maxLength={512}
71+
autoComplete="off"
72+
aria-autocomplete="list"
73+
aria-haspopup="listbox"
74+
aria-expanded={value && isOpen ? 'true' : 'false'}
75+
clearButton
76+
keyboardShortcut={<KeyboardShortcut keys={isOpen ? ['esc'] : ['mod', 'k']} />}
77+
{...rest}
78+
type="text"
79+
/>
80+
</div>
7981
);
8082
}
8183
);

packages/gitbook/src/components/primitives/Input.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const Input = React.forwardRef<HTMLInputElement | HTMLTextAreaElement, In
133133
type="text"
134134
ref={ref as React.Ref<HTMLInputElement>}
135135
value={value}
136+
size={1} // This will make the input have the smallest possible width (1 character) so we can grow it with flexbox
136137
onKeyDown={(event) => {
137138
if (event.key === 'Enter' && !event.shiftKey && value.toString().trim()) {
138139
event.preventDefault();
@@ -206,7 +207,11 @@ export const Input = React.forwardRef<HTMLInputElement | HTMLTextAreaElement, In
206207
hasValue ? 'group-focus-within/input:flex' : ''
207208
)}
208209
onClick={() => {
209-
setValue('');
210+
handleChange({
211+
target: {
212+
value: '',
213+
},
214+
} as React.ChangeEvent<HybridInputElement>);
210215
}}
211216
/>
212217
) : null}
@@ -226,7 +231,7 @@ export const Input = React.forwardRef<HTMLInputElement | HTMLTextAreaElement, In
226231
</div>
227232
</div>
228233
{trailing || submitButton || maxLength ? (
229-
<div className="flex items-center gap-2">
234+
<div className="flex items-center gap-2 empty:hidden">
230235
{trailing ? trailing : null}
231236
{maxLength && !submitted && value.toString().length > maxLength * 0.8 ? (
232237
<span

packages/gitbook/src/components/primitives/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from './Popover';
1313
export * from './LoadingStateProvider';
1414
export * from './HoverCard';
1515
export * from './DropdownMenu';
16+
export * from './Input';

0 commit comments

Comments
 (0)