Skip to content

Commit

Permalink
fix: add missing readOnly state to External fields
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Sep 16, 2024
1 parent 1a69125 commit bf1449d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const ExternalField = ({
label,
Label,
id,
readOnly,
}: FieldPropsInternal) => {
// DEPRECATED
const validField = field as ExternalFieldType;
Expand Down Expand Up @@ -56,6 +57,7 @@ export const ExternalField = ({
onChange={onChange}
value={value}
id={id}
readOnly={readOnly}
/>
</Label>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/core/components/ExternalInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const ExternalInput = ({
value = null,
name,
id,
readOnly,
}: {
field: ExternalField;
onChange: (value: any) => void;
value: any;
name?: string;
id: string;
readOnly?: boolean;
}) => {
const {
mapProp = (val: any) => val,
Expand Down Expand Up @@ -91,6 +93,7 @@ export const ExternalInput = ({
className={getClassName({
dataSelected: !!value,
modalVisible: isOpen,
readOnly,
})}
id={id}
>
Expand All @@ -99,6 +102,7 @@ export const ExternalInput = ({
type="button"
onClick={() => setOpen(true)}
className={getClassName("button")}
disabled={readOnly}
>
{/* NB this is hardcoded to strapi for now */}
{value ? (
Expand All @@ -121,6 +125,7 @@ export const ExternalInput = ({
onClick={() => {
onChange(null);
}}
disabled={readOnly}
>
<Unlock size={16} />
</button>
Expand Down
19 changes: 12 additions & 7 deletions packages/core/components/ExternalInput/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
border: 1px solid var(--puck-color-grey-09);
border-radius: 4px;
color: var(--puck-color-azure-04);
cursor: pointer;
padding: 12px 16px;
font-weight: 500;
white-space: nowrap;
Expand All @@ -29,13 +28,16 @@
border-bottom-right-radius: 0px;
}

.ExternalInput--readOnly .ExternalInput-button {
background-color: var(--puck-color-grey-11);
}

.ExternalInput-detachButton {
border: 1px solid var(--puck-color-grey-09);
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
background-color: var(--puck-color-grey-12);
color: var(--puck-color-grey-05);
cursor: pointer;
display: flex;
gap: 8px;
align-items: center;
Expand All @@ -54,19 +56,22 @@
}

@media (hover: hover) and (pointer: fine) {
.ExternalInput-button:hover,
.ExternalInput-detachButton:hover {
.ExternalInput:not(.ExternalInput--readOnly) .ExternalInput-button:hover,
.ExternalInput:not(.ExternalInput--readOnly)
.ExternalInput-detachButton:hover {
background: var(--puck-color-azure-12);
transition: none;
}

.ExternalInput-detachButton:hover {
.ExternalInput:not(.ExternalInput--readOnly)
.ExternalInput-detachButton:hover {
color: var(--puck-color-azure-04);
}
}

.ExternalInput-button:active,
.ExternalInput-detachButton:active {
.ExternalInput:not(.ExternalInput--readOnly) .ExternalInput-button:active,
.ExternalInput:not(.ExternalInput--readOnly)
.ExternalInput-detachButton:active {
background: var(--puck-color-azure-11);
transition: none;
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/lib/use-resolved-permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useCallback, useEffect, useState } from "react";
import { flattenData } from "./flatten-data";
import { ComponentData, Config, Permissions, UserGenerics } from "../types";
import { getChanged } from "./get-changed";
import { AppContext } from "../components/Puck/context";

type PermissionsArgs<
UserConfig extends Config = Config,
Expand Down

0 comments on commit bf1449d

Please sign in to comment.