Skip to content

Commit

Permalink
fix: fix chip font size in dropdown & use onSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
thaisguigon committed May 1, 2024
1 parent a3edd97 commit 821f3b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const FieldInput = ({
onShiftTab={onShiftTab}
/>
) : isFieldLinks(fieldDefinition) ? (
<LinksFieldInput onCancel={onCancel} />
<LinksFieldInput onCancel={onCancel} onSubmit={onSubmit} />
) : isFieldCurrency(fieldDefinition) ? (
<CurrencyFieldInput
onEnter={onEnter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Key } from 'ts-key-enum';
import { IconPlus } from 'twenty-ui';

import { useLinksField } from '@/object-record/record-field/meta-types/hooks/useLinksField';
import { FieldInputEvent } from '@/object-record/record-field/types/FieldInputEvent';
import { LinkDisplay } from '@/ui/field/display/components/LinkDisplay';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu';
Expand All @@ -23,9 +24,13 @@ const StyledDropdownMenu = styled(DropdownMenu)`

export type LinksFieldInputProps = {
onCancel?: () => void;
onSubmit?: FieldInputEvent;
};

export const LinksFieldInput = ({ onCancel }: LinksFieldInputProps) => {
export const LinksFieldInput = ({
onCancel,
onSubmit,
}: LinksFieldInputProps) => {
const { persistLinksField, hotkeyScope, fieldValue } = useLinksField();

const containerRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -75,22 +80,26 @@ export const LinksFieldInput = ({ onCancel }: LinksFieldInputProps) => {
setInputValue('');

if (!links.length) {
persistLinksField({
primaryLinkUrl: inputValue,
primaryLinkLabel: '',
secondaryLinks: [],
});
onSubmit?.(() =>
persistLinksField({
primaryLinkUrl: inputValue,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);

return;
}

persistLinksField({
...fieldValue,
secondaryLinks: [
...(fieldValue.secondaryLinks ?? []),
{ label: '', url: inputValue },
],
});
onSubmit?.(() =>
persistLinksField({
...fieldValue,
secondaryLinks: [
...(fieldValue.secondaryLinks ?? []),
{ label: '', url: inputValue },
],
}),
);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import { getUrlHostName } from '~/utils/url/getUrlHostName';
import { EllipsisDisplay } from './EllipsisDisplay';

const StyledRawLink = styled(RoundedLink)`
overflow: hidden;
a {
overflow: hidden;
text-overflow: ellipsis;
font-size: ${({ theme }) => theme.font.size.md};
white-space: nowrap;
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Chip, ChipSize, ChipVariant } from 'twenty-ui';
type RoundedLinkProps = {
href: string;
children?: React.ReactNode;
className?: string;
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
};

Expand All @@ -27,10 +28,15 @@ const StyledChip = styled(Chip)`
padding: ${({ theme }) => theme.spacing(2)};
`;

export const RoundedLink = ({ children, href, onClick }: RoundedLinkProps) => (
export const RoundedLink = ({
children,
className,
href,
onClick,
}: RoundedLinkProps) => (
<div>
{children !== '' ? (
<StyledClickable>
<StyledClickable className={className}>
<ReactLink target="_blank" to={href} onClick={onClick}>
<StyledChip
label={`${children}`}
Expand Down

0 comments on commit 821f3b7

Please sign in to comment.