Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Option list changes width on hover #4363

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Option list changes width on hover
  • Loading branch information
istarkov committed Nov 4, 2024
commit 3eba9de923e36580ae18c9e85426d4499c375759
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ export const PositionControl = ({
<Flex direction="column" gap="1">
<PropertyInlineLabel
label="Position"
description={
propertyDescriptions[property as keyof typeof propertyDescriptions]
}
description={propertyDescriptions[property]}
properties={[property]}
/>
<Flex gap="6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getRepeatedStyleItem,
setRepeatedStyleItem,
} from "../../shared/repeated-style";
import { noCase } from "change-case";

export const SelectControl = ({
property,
Expand Down Expand Up @@ -50,6 +51,12 @@ export const SelectControl = ({
options.push(valueString);
}

const hasDescription =
options.length > 0 &&
options.some(
(option) => declarationDescriptions[`${property}:${option}`] !== undefined
);

return (
<Select
// Show empty field instead of radix placeholder like css value input does.
Expand Down Expand Up @@ -77,15 +84,16 @@ export const SelectControl = ({
}
}}
getDescription={(option) => {
const description =
declarationDescriptions[
`${property}:${option}` as keyof typeof declarationDescriptions
];

if (description === undefined) {
if (hasDescription === false) {
return;
}
return <Box css={{ width: theme.spacing[26] }}>{description}</Box>;

const description = declarationDescriptions[`${property}:${option}`];
return (
<Box css={{ width: theme.spacing[26] }}>
{description ?? `The ${noCase(property)} is ${option}`}
</Box>
);
}}
getItemProps={() => ({ text: "sentence" })}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const PropertyLabel = ({
properties,
}: {
label: string;
description: string;
description?: string;
properties: [StyleProperty, ...StyleProperty[]];
}) => {
const styles = useComputedStyles(properties);
Expand Down Expand Up @@ -344,7 +344,7 @@ export const PropertyInlineLabel = ({
}: {
label: string;
title?: string;
description: string;
description?: string;
properties?: [StyleProperty, ...StyleProperty[]];
disabled?: boolean;
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ const matchOrSuggestToCreate = (
};

const getNewPropertyDescription = (item: null | SearchItem) => {
let description = `Create CSS variable.`;
let description: string | undefined = `Create CSS variable.`;
if (item && item.value in propertyDescriptions) {
description =
propertyDescriptions[item.value as keyof typeof propertyDescriptions];
description = propertyDescriptions[item.value];
}
return <Box css={{ width: theme.spacing[28] }}>{description}</Box>;
};
Expand Down Expand Up @@ -261,8 +260,7 @@ const AdvancedSearch = ({
const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
const styleDecl = useComputedStyleDecl(property);
const label = hyphenateProperty(property);
const description =
propertyDescriptions[property as keyof typeof propertyDescriptions];
const description = propertyDescriptions[property];
const color =
styleDecl.source.name === "default" ? "code" : styleDecl.source.name;
const [isOpen, setIsOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ const GapTooltip = ({
children: ReactNode;
}) => {
const [isOpen, setIsOpen] = useState(false);
const description =
propertyDescriptions[
styleDecl.property as keyof typeof propertyDescriptions
];
const description = propertyDescriptions[styleDecl.property];
return (
<Tooltip
open={isOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const SizeProperty = ({ property }: { property: StyleProperty }) => {
<Grid gap={1}>
<PropertyLabel
label={humanizeString(property)}
description={
propertyDescriptions[property as keyof typeof propertyDescriptions]
}
description={propertyDescriptions[property]}
properties={[property]}
/>
<TextControl property={property} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ export const TransformAndPerspectiveOrigin = ({
<Grid gap="2">
<PropertyLabel
label={label}
description={
propertyDescriptions[property as keyof typeof propertyDescriptions]
}
description={propertyDescriptions[property]}
properties={[property]}
/>
<Flex gap="6">
Expand Down
2 changes: 1 addition & 1 deletion packages/css-data/bin/property-value-descriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function writeFile(descriptions: Record<string, unknown>) {
([binding, value]) =>
`export const ${binding} = ` +
(typeof value === "string" ? value : JSON.stringify(value, null, 2)) +
" as const;"
" as Record<string, string | undefined>;"
)
.join("\n\n");

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading