Skip to content

Commit 9472e58

Browse files
committed
Clean up CMS Starter
Move all styles to App.css. Drop unnecessary tabIndex. Use ManagedCollectionFieldInput instead of deprecated EditableManagedCollectionField. Other minor fixes.
1 parent 5fc5abb commit 9472e58

File tree

3 files changed

+47
-41
lines changed

3 files changed

+47
-41
lines changed

starters/cms/src/App.css

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ form {
2424
top: 0;
2525
}
2626

27-
.field-input {
27+
select {
2828
width: 100%;
29+
}
30+
31+
select:disabled,
32+
input[type="text"]:disabled,
33+
.ignored {
34+
opacity: 0.5;
35+
}
36+
37+
.mapping select {
2938
flex-shrink: 1;
3039
}
3140

@@ -88,10 +97,6 @@ form {
8897
color: var(--framer-color-text-secondary);
8998
}
9099

91-
.setup select {
92-
width: 100%;
93-
}
94-
95100
.mapping {
96101
padding-bottom: 0;
97102
}
@@ -130,10 +135,6 @@ form {
130135
gap: 8px;
131136
}
132137

133-
.mapping .source-field[aria-disabled="true"] {
134-
opacity: 0.5;
135-
}
136-
137138
.mapping .source-field:focus-visible {
138139
outline: none;
139140
box-shadow: inset 0 0 0 1px var(--framer-color-tint);
@@ -147,14 +148,18 @@ form {
147148
box-shadow: none;
148149
}
149150

150-
[data-framer-theme=light] .mapping .source-field input[type="checkbox"]:not(:checked) {
151+
[data-framer-theme="light"] .mapping .source-field input[type="checkbox"]:not(:checked) {
151152
background: #ccc;
152153
}
153154

154-
[data-framer-theme=dark] .mapping .source-field input[type="checkbox"]:not(:checked) {
155+
[data-framer-theme="dark"] .mapping .source-field input[type="checkbox"]:not(:checked) {
155156
background: #666;
156157
}
157158

159+
.mapping input[type="text"] {
160+
width: 100%;
161+
}
162+
158163
.mapping footer {
159164
position: sticky;
160165
bottom: 0;
@@ -178,3 +183,7 @@ form {
178183
background: linear-gradient(to bottom, transparent, var(--framer-color-bg));
179184
pointer-events: none;
180185
}
186+
187+
.mapping footer > button {
188+
text-transform: capitalize;
189+
}

starters/cms/src/FieldMapping.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import { type EditableManagedCollectionField, framer, type ManagedCollection } from "framer-plugin"
1+
import { type ManagedCollectionFieldInput, framer, type ManagedCollection } from "framer-plugin"
22
import { useEffect, useState } from "react"
33
import { type DataSource, dataSourceOptions, mergeFieldsWithExistingFields, syncCollection } from "./data"
44

55
interface FieldMappingRowProps {
6-
field: EditableManagedCollectionField
6+
field: ManagedCollectionFieldInput
77
originalFieldName: string | undefined
8-
disabled: boolean
8+
isIgnored: boolean
99
onToggleDisabled: (fieldId: string) => void
1010
onNameChange: (fieldId: string, name: string) => void
1111
}
1212

13-
function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled, onNameChange }: FieldMappingRowProps) {
13+
function FieldMappingRow({
14+
field,
15+
originalFieldName,
16+
isIgnored,
17+
onToggleDisabled,
18+
onNameChange,
19+
}: FieldMappingRowProps) {
1420
return (
1521
<>
1622
<button
1723
type="button"
18-
className="source-field"
19-
aria-disabled={disabled}
24+
className={`source-field ${isIgnored ? "ignored" : ""}`}
2025
onClick={() => onToggleDisabled(field.id)}
21-
tabIndex={0}
2226
>
23-
<input type="checkbox" checked={!disabled} tabIndex={-1} readOnly />
27+
<input type="checkbox" checked={!isIgnored} tabIndex={-1} readOnly />
2428
<span>{originalFieldName ?? field.id}</span>
2529
</button>
2630
<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" fill="none">
@@ -35,8 +39,7 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
3539
</svg>
3640
<input
3741
type="text"
38-
style={{ width: "100%", opacity: disabled ? 0.5 : 1 }}
39-
disabled={disabled}
42+
disabled={isIgnored}
4043
placeholder={field.id}
4144
value={field.name}
4245
onChange={event => onNameChange(field.id, event.target.value)}
@@ -50,7 +53,7 @@ function FieldMappingRow({ field, originalFieldName, disabled, onToggleDisabled,
5053
)
5154
}
5255

53-
const initialManagedCollectionFields: EditableManagedCollectionField[] = []
56+
const initialManagedCollectionFields: ManagedCollectionFieldInput[] = []
5457
const initialFieldIds: ReadonlySet<string> = new Set()
5558

5659
interface FieldMappingProps {
@@ -68,7 +71,7 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
6871

6972
const [possibleSlugFields] = useState(() => dataSource.fields.filter(field => field.type === "string"))
7073

71-
const [selectedSlugField, setSelectedSlugField] = useState<EditableManagedCollectionField | null>(
74+
const [selectedSlugField, setSelectedSlugField] = useState<ManagedCollectionFieldInput | null>(
7275
possibleSlugFields.find(field => field.id === initialSlugFieldId) ?? possibleSlugFields[0] ?? null
7376
)
7477

@@ -204,23 +207,17 @@ export function FieldMapping({ collection, dataSource, initialSlugFieldId }: Fie
204207
key={`field-${field.id}`}
205208
field={field}
206209
originalFieldName={dataSource.fields.find(sourceField => sourceField.id === field.id)?.name}
207-
disabled={ignoredFieldIds.has(field.id)}
210+
isIgnored={ignoredFieldIds.has(field.id)}
208211
onToggleDisabled={toggleFieldDisabledState}
209212
onNameChange={changeFieldName}
210213
/>
211214
))}
212215
</div>
213216

214217
<footer>
215-
<hr className="sticky-top" />
216-
<button disabled={isSyncing} tabIndex={0}>
217-
{isSyncing ? (
218-
<div className="framer-spinner" />
219-
) : (
220-
<span>
221-
Import <span style={{ textTransform: "capitalize" }}>{dataSourceName}</span>
222-
</span>
223-
)}
218+
<hr />
219+
<button disabled={isSyncing}>
220+
{isSyncing ? <div className="framer-spinner" /> : `Import ${dataSourceName}`}
224221
</button>
225222
</footer>
226223
</form>

starters/cms/src/data.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
type EditableManagedCollectionField,
2+
type ManagedCollectionFieldInput,
33
type FieldDataInput,
44
framer,
55
type ManagedCollection,
@@ -13,7 +13,7 @@ export const PLUGIN_KEYS = {
1313

1414
export interface DataSource {
1515
id: string
16-
fields: readonly EditableManagedCollectionField[]
16+
fields: readonly ManagedCollectionFieldInput[]
1717
items: FieldDataInput[]
1818
}
1919

@@ -44,7 +44,7 @@ export async function getDataSource(dataSourceId: string, abortSignal?: AbortSig
4444
const dataSource = await dataSourceResponse.json()
4545

4646
// Map your source fields to supported field types in Framer
47-
const fields: EditableManagedCollectionField[] = []
47+
const fields: ManagedCollectionFieldInput[] = []
4848
for (const field of dataSource.fields) {
4949
switch (field.type) {
5050
case "string":
@@ -83,9 +83,9 @@ export async function getDataSource(dataSourceId: string, abortSignal?: AbortSig
8383
}
8484

8585
export function mergeFieldsWithExistingFields(
86-
sourceFields: readonly EditableManagedCollectionField[],
87-
existingFields: readonly EditableManagedCollectionField[]
88-
): EditableManagedCollectionField[] {
86+
sourceFields: readonly ManagedCollectionFieldInput[],
87+
existingFields: readonly ManagedCollectionFieldInput[]
88+
): ManagedCollectionFieldInput[] {
8989
return sourceFields.map(sourceField => {
9090
const existingField = existingFields.find(existingField => existingField.id === sourceField.id)
9191
if (existingField) {
@@ -98,8 +98,8 @@ export function mergeFieldsWithExistingFields(
9898
export async function syncCollection(
9999
collection: ManagedCollection,
100100
dataSource: DataSource,
101-
fields: readonly EditableManagedCollectionField[],
102-
slugField: EditableManagedCollectionField
101+
fields: readonly ManagedCollectionFieldInput[],
102+
slugField: ManagedCollectionFieldInput
103103
) {
104104
const sanitizedFields = fields.map(field => ({
105105
...field,

0 commit comments

Comments
 (0)