3bfdc2c83f
## Summary
Continues the Emotion → Linaria migration (PR 4-6 from the [migration
plan](docs/emotion-to-linaria-migration-plan.md)). Migrates **311
files** across four module groups:
| Module | Files |
|---|---|
| command-menu | 53 |
| workflow | 84 |
| page-layout | 84 |
| UI (partial - first ~80 files) | ~80 |
| twenty-ui (TEXT_INPUT_STYLE) | 1 |
| misc (hooks, keyboard-shortcut-menu, file-upload) | ~9 |
### Migration patterns applied
- `import styled from '@emotion/styled'` → `import { styled } from
'@linaria/react'`
- `import { useTheme } from '@emotion/react'` → `import { useContext }
from 'react'` + `import { ThemeContext } from 'twenty-ui/theme'`
- `${({ theme }) => theme.X.Y.Z}` → `${themeCssVariables.X.Y.Z}` (static
CSS variables)
- `theme.spacing(N)` → `themeCssVariables.spacing[N]`
- `styled(motion.div)` → `motion.create(StyledBase)` (11 components)
- `styled(Component)<TypeParams>` → wrapper div approach for non-HTML
elements
- Multi-declaration interpolations split into one CSS property per
interpolation
- Interpolation return types fixed (`&&` → ternary `? : ''`)
- `TEXT_INPUT_STYLE` converted from function to static string constant
(backward compatible)
- Emotion `<Global>` replaced with `useEffect` style injection
- Complex runtime-dependent styles use CSS custom properties via
`style={}` prop
### After this PR
- **Remaining files**: ~400 (object-record: ~160, settings: ~200, UI:
~44)
- **No breaking changes**: CSS variables resolve identically to the
previous Emotion theme values
118 lines
3.0 KiB
TypeScript
118 lines
3.0 KiB
TypeScript
import { styled } from '@linaria/react';
|
|
import { useEffect, useRef, useState, type ChangeEvent } from 'react';
|
|
import TextareaAutosize from 'react-textarea-autosize';
|
|
|
|
import { LightCopyIconButton } from '@/object-record/record-field/ui/components/LightCopyIconButton';
|
|
import { useRegisterInputEvents } from '@/object-record/record-field/ui/meta-types/input/hooks/useRegisterInputEvents';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { TEXT_INPUT_STYLE } from 'twenty-ui/theme';
|
|
import { turnIntoEmptyStringIfWhitespacesOnly } from '~/utils/string/turnIntoEmptyStringIfWhitespacesOnly';
|
|
import { themeCssVariables } from 'twenty-ui/theme-constants';
|
|
|
|
export type TextAreaInputProps = {
|
|
instanceId: string;
|
|
disabled?: boolean;
|
|
className?: string;
|
|
placeholder?: string;
|
|
autoFocus?: boolean;
|
|
value: string;
|
|
onEnter: (newText: string) => void;
|
|
onEscape: (newText: string) => void;
|
|
onTab?: (newText: string) => void;
|
|
onShiftTab?: (newText: string) => void;
|
|
onClickOutside: (event: MouseEvent | TouchEvent, inputValue: string) => void;
|
|
onChange?: (newText: string) => void;
|
|
maxRows?: number;
|
|
copyButton?: boolean;
|
|
};
|
|
|
|
const StyledTextArea = styled(TextareaAutosize)`
|
|
${TEXT_INPUT_STYLE}
|
|
align-items: center;
|
|
display: flex;
|
|
justify-content: center;
|
|
resize: none;
|
|
max-height: 400px;
|
|
width: calc(100% - ${themeCssVariables.spacing[7]});
|
|
|
|
line-height: 18px;
|
|
`;
|
|
|
|
const StyledLightIconButtonContainer = styled.div`
|
|
background: transparent;
|
|
position: absolute;
|
|
top: 16px;
|
|
transform: translateY(-50%);
|
|
right: 0;
|
|
`;
|
|
|
|
export const TextAreaInput = ({
|
|
instanceId,
|
|
disabled,
|
|
className,
|
|
placeholder,
|
|
autoFocus,
|
|
value,
|
|
onEnter,
|
|
onEscape,
|
|
onTab,
|
|
onShiftTab,
|
|
onClickOutside,
|
|
onChange,
|
|
maxRows,
|
|
copyButton = true,
|
|
}: TextAreaInputProps) => {
|
|
const [internalText, setInternalText] = useState(value);
|
|
const handleChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
|
|
const targetValue = turnIntoEmptyStringIfWhitespacesOnly(
|
|
event.target.value,
|
|
);
|
|
setInternalText(targetValue);
|
|
onChange?.(targetValue);
|
|
};
|
|
|
|
const wrapperRef = useRef<HTMLTextAreaElement>(null);
|
|
const copyRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (isDefined(wrapperRef.current)) {
|
|
wrapperRef.current.setSelectionRange(
|
|
wrapperRef.current.value.length,
|
|
wrapperRef.current.value.length,
|
|
);
|
|
}
|
|
}, []);
|
|
|
|
useRegisterInputEvents({
|
|
focusId: instanceId,
|
|
inputRef: wrapperRef,
|
|
copyRef: copyRef,
|
|
inputValue: internalText,
|
|
onEnter,
|
|
onEscape,
|
|
onClickOutside,
|
|
onTab,
|
|
onShiftTab,
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<StyledTextArea
|
|
placeholder={placeholder}
|
|
disabled={disabled}
|
|
className={className}
|
|
ref={wrapperRef}
|
|
onChange={handleChange}
|
|
autoFocus={autoFocus}
|
|
value={internalText}
|
|
maxRows={maxRows}
|
|
/>
|
|
{copyButton && (
|
|
<StyledLightIconButtonContainer ref={copyRef}>
|
|
<LightCopyIconButton copyText={internalText} />
|
|
</StyledLightIconButtonContainer>
|
|
)}
|
|
</>
|
|
);
|
|
};
|