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

Add variants to link to media #1522

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { CheckBox } from "@/legacy/lib/forms/fields";
import {
DisplayTextCheckbox,
RepeatableCheckbox,
Variants,
Variants as VariantsForm,
} from "./components";

const FormFields = {
Expand Down Expand Up @@ -82,7 +82,7 @@ const Form = (props) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
setFieldValue={setFieldValue}
/>
<VariantsWrapper variants={variants} setFieldValue={setFieldValue} />
<Variants variants={variants} setFieldValue={setFieldValue} />
</Box>
</>
);
Expand All @@ -91,7 +91,7 @@ const Form = (props) => {
export { FormFields };
export default Form;

function VariantsWrapper({ variants, setFieldValue }) {
export function Variants({ variants, setFieldValue }) {
const fieldKey = "config.variants";

const onVariantsChange = (newVariants) =>
Expand All @@ -102,7 +102,7 @@ function VariantsWrapper({ variants, setFieldValue }) {
const error = meta.error?.find((err) => err);

return (
<Variants
<VariantsForm
variants={variants}
onVariantsChange={onVariantsChange}
error={error}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

import { Box } from "@prismicio/editor-ui";

import { Col, Flex as FlexGrid } from "@/legacy/components/Flex";
import WidgetFormField from "@/legacy/lib/builders/common/EditModal/Field";
import { createFieldNameFromKey } from "@/legacy/lib/forms";
import { DefaultFields } from "@/legacy/lib/forms/defaults";

import { DisplayTextCheckbox } from "../Link/components";
import { Variants } from "../Link/Form";

const FormFields = {
...DefaultFields,
Expand All @@ -15,11 +20,11 @@ const Form = (props) => {

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {
config: { allowText },
config: { allowText, variants },
} = formValues;

return (
<>
<Box flexDirection="column" gap={16}>
<FlexGrid>
{Object.entries(FormFields).map(([key, field]) => (
<Col key={key}>
Expand All @@ -40,7 +45,8 @@ const Form = (props) => {
setFieldValue={setFieldValue}
/>
</FlexGrid>
</>
<Variants variants={variants} setFieldValue={setFieldValue} />
</Box>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const LinkToMediaWidget: Widget<Link, typeof schema> = {
placeholder: "",
select: "media",
allowText: true,
repeat: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this was here but IMO it's not needed and it's misleading because there's no repeat in link to media

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was because of the first version of types internal, when it was required to set repeat

},
}),
TYPE_NAME: "Link",
Expand Down
Loading