@airtable/blocks/ui#FormField JavaScript Examples
The following examples show how to use
@airtable/blocks/ui#FormField.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From apps-simple-chart with MIT License | 6 votes |
function Settings({table}) {
return (
<Box display="flex" padding={3} borderBottom="thick">
<FormField label="Table" width="33.33%" paddingRight={1} marginBottom={0}>
<TablePickerSynced globalConfigKey={GlobalConfigKeys.TABLE_ID} />
</FormField>
{table && (
<FormField label="View" width="33.33%" paddingX={1} marginBottom={0}>
<ViewPickerSynced table={table} globalConfigKey={GlobalConfigKeys.VIEW_ID} />
</FormField>
)}
{table && (
<FormField label="X-axis field" width="33.33%" paddingLeft={1} marginBottom={0}>
<FieldPickerSynced
table={table}
globalConfigKey={GlobalConfigKeys.X_FIELD_ID}
/>
</FormField>
)}
</Box>
);
}
Example #2
Source File: settings.js From neighbor-express with MIT License | 6 votes |
// A UI component for setting a key in the global config.
// key can be a string (for a top level key) or a list of strings (for a nested value)
function InputSetter({ label, description, keyOrPath }) {
const globalConfig = useGlobalConfig();
return (
<FormField label={label} description={description}>
<InputSynced
globalConfigKey={keyOrPath}
disabled={!globalConfig.hasPermissionToSet(keyOrPath)}
/>
</FormField>
);
}
Example #3
Source File: settings.js From neighbor-express with MIT License | 6 votes |
function FieldSetter({
label,
description,
keyOrPath,
tableName,
...setterProps
}) {
const globalConfig = useGlobalConfig();
const base = useBase();
const table = base.getTableByNameIfExists(tableName);
function setField(newField) {
globalConfig.setAsync(keyOrPath, newField.id);
}
// If table is null or undefined, the FieldPicker will not render.
return (
<FormField label={label} description={description}>
<FieldPicker
table={table}
field={table.getFieldIfExists(globalConfig.get(keyOrPath))}
onChange={setField}
disabled={!globalConfig.hasPermissionToSet(keyOrPath)}
{...setterProps}
/>
</FormField>
);
}
Example #4
Source File: settings.js From neighbor-express with MIT License | 6 votes |
function AddEmailTypeDialog() {
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [name, setName] = useState("");
const globalConfig = useGlobalConfig();
function save() {
globalConfig.setAsync(["email_types", name], {});
setIsDialogOpen(false);
}
return (
<>
<Button onClick={() => setIsDialogOpen(true)}>Add new email type</Button>
{isDialogOpen && (
<Dialog onClose={() => setIsDialogOpen(false)} width="320px">
<Dialog.CloseButton />
<Heading>New Email Type</Heading>
<FormField
label="Name"
description="A short descriptive name of the new type of email"
>
<Input value={name} onChange={(e) => setName(e.target.value)} />
</FormField>
<Button onClick={save}>Save</Button>
</Dialog>
)}
</>
);
}
Example #5
Source File: settings.js From neighbor-express with MIT License | 6 votes |
export function SettingsComponent({ exit }) {
const globalConfig = useGlobalConfig();
return (
<Box padding={3}>
<Button variant="primary" onClick={exit} style={{ float: "right" }}>
Exit settings
</Button>
<h1> Settings </h1>
<p>
You probably won't need to do anything here unless you're just starting
out.
</p>
<FormField label="Galaxy Digital API Key">
<InputSynced globalConfigKey="GALAXY_DIGITAL_API_KEY" />
</FormField>
</Box>
);
}
Example #6
Source File: SettingsForm.js From apps-flashcard with MIT License | 5 votes |
export default function SettingsForm({setIsSettingsVisible, settings}) {
return (
<Box
flex="none"
display="flex"
flexDirection="column"
width="300px"
backgroundColor="white"
maxHeight="100vh"
borderLeft="thick"
>
<Box
flex="auto"
display="flex"
flexDirection="column"
minHeight="0"
padding={3}
overflowY="auto"
>
<Heading marginBottom={3}>Settings</Heading>
<FormField label="Table">
<TablePickerSynced globalConfigKey={ConfigKeys.TABLE_ID} />
</FormField>
{settings.table && (
<Fragment>
<FormField
label="View"
description="Only records in this view will be used"
>
<ViewPickerSynced
table={settings.table}
globalConfigKey={ConfigKeys.VIEW_ID}
/>
</FormField>
<FormField label="Question field">
<FieldPickerSynced
table={settings.table}
globalConfigKey={ConfigKeys.QUESTION_FIELD_ID}
/>
</FormField>
<FormField label="Answer field (optional)">
<FieldPickerSynced
table={settings.table}
shouldAllowPickingNone={true}
globalConfigKey={ConfigKeys.ANSWER_FIELD_ID}
/>
</FormField>
</Fragment>
)}
</Box>
<Box
flex="none"
display="flex"
justifyContent="flex-end"
paddingY={3}
marginX={3}
borderTop="thick"
>
<Button variant="primary" size="large" onClick={() => setIsSettingsVisible(false)}>
Done
</Button>
</Box>
</Box>
);
}
Example #7
Source File: todo-app.js From apps-todo-list with MIT License | 5 votes |
export default function TodoApp() {
const base = useBase();
// Read the user's choice for which table and view to use from globalConfig.
const globalConfig = useGlobalConfig();
const tableId = globalConfig.get('selectedTableId');
const viewId = globalConfig.get('selectedViewId');
const doneFieldId = globalConfig.get('selectedDoneFieldId');
const table = base.getTableByIdIfExists(tableId);
const view = table ? table.getViewByIdIfExists(viewId) : null;
const doneField = table ? table.getFieldByIdIfExists(doneFieldId) : null;
// Don't need to fetch records if doneField doesn't exist (the field or it's parent table may
// have been deleted, or may not have been selected yet.)
const records = useRecords(doneField ? view : null, {
fields: doneField ? [table.primaryField, doneField] : [],
});
const tasks = records
? records.map(record => {
return <Task key={record.id} record={record} table={table} doneField={doneField} />;
})
: null;
return (
<div>
<Box padding={3} borderBottom="thick">
<FormField label="Table">
<TablePickerSynced globalConfigKey="selectedTableId" />
</FormField>
<FormField label="View">
<ViewPickerSynced table={table} globalConfigKey="selectedViewId" />
</FormField>
<FormField label="Field" marginBottom={0}>
<FieldPickerSynced
table={table}
globalConfigKey="selectedDoneFieldId"
placeholder="Pick a 'done' field..."
allowedTypes={[FieldType.CHECKBOX]}
/>
</FormField>
</Box>
{tasks}
{table && doneField && <AddTaskForm table={table} />}
</div>
);
}
Example #8
Source File: SettingsForm.js From apps-url-preview with MIT License | 5 votes |
function SettingsForm({setIsSettingsOpen}) {
const globalConfig = useGlobalConfig();
const {
isValid,
message,
settings: {isEnforced, urlTable},
} = useSettings();
const canUpdateSettings = globalConfig.hasPermissionToSet();
return (
<Box
position="absolute"
top={0}
bottom={0}
left={0}
right={0}
display="flex"
flexDirection="column"
>
<Box flex="auto" padding={4} paddingBottom={2}>
<Heading marginBottom={3}>Settings</Heading>
<FormField label="">
<Switch
aria-label="When enabled, the app will only show previews for the specified table and field, regardless of what field is selected."
value={isEnforced}
onChange={value => {
globalConfig.setAsync(ConfigKeys.IS_ENFORCED, value);
}}
disabled={!canUpdateSettings}
label="Use a specific field for previews"
/>
<Text paddingY={1} textColor="light">
{isEnforced
? 'The app will show previews for the selected record in grid view if the table has a supported URL in the specified field.'
: 'The app will show previews if the selected cell in grid view has a supported URL.'}
</Text>
</FormField>
{isEnforced && (
<FormField label="Preview table">
<TablePickerSynced globalConfigKey={ConfigKeys.URL_TABLE_ID} />
</FormField>
)}
{isEnforced && urlTable && (
<FormField label="Preview field">
<FieldPickerSynced
table={urlTable}
globalConfigKey={ConfigKeys.URL_FIELD_ID}
allowedTypes={allowedUrlFieldTypes}
/>
</FormField>
)}
</Box>
<Box display="flex" flex="none" padding={3} borderTop="thick">
<Box
flex="auto"
display="flex"
alignItems="center"
justifyContent="flex-end"
paddingRight={2}
>
<Text textColor="light">{message}</Text>
</Box>
<Button
disabled={!isValid}
size="large"
variant="primary"
onClick={() => setIsSettingsOpen(false)}
>
Done
</Button>
</Box>
</Box>
);
}
Example #9
Source File: settings.js From neighbor-express with MIT License | 5 votes |
function EmailTypeSettings({ emailType }) {
const globalConfig = useGlobalConfig();
const audienceOptions = [
{ value: "volunteer", label: "Volunteer" },
{ value: "recipient", label: "Delivery Recipient" },
];
const deliveriesTable = useBase().getTableByNameIfExists("Deliveries");
const triggerField = deliveriesTable.getFieldIfExists(
globalConfig.get("trigger_column")
);
const stageOptions = triggerField?.options.choices.map((choice) => {
return {
value: choice.id,
label: choice.name,
};
});
function deleteMe() {
globalConfig.setAsync(["email_types", emailType], undefined);
}
return (
<Box padding={3}>
<TextButton onClick={deleteMe} icon="trash" style={{ float: "right" }}>
Delete
</TextButton>
<Accordion title={emailType}>
<InputSetter
label="Sendgrid Template ID"
description="Find this in the Sendgrid UI. Looks like d-ea13bf1f408947829fa19779eade8250"
keyOrPath={["email_types", emailType, "sendgrid_template"]}
/>
<FormField
label="Send to..."
description="Who should this email be sent to?"
>
<SelectButtonsSynced
globalConfigKey={["email_types", emailType, "audience"]}
options={audienceOptions}
width="320px"
/>
</FormField>
<FormField
label="Send when..."
description={`Email will be sent when ${triggerField.name} column is...`}
>
<SelectSynced
globalConfigKey={["email_types", emailType, "stage"]}
options={stageOptions}
width="320px"
/>
</FormField>
</Accordion>
</Box>
);
}
Example #10
Source File: settings.js From neighbor-express with MIT License | 5 votes |
function AddTemplateVariableDialog({ table }) {
const [isDialogOpen, setIsDialogOpen] = useState(false);
const [field, setField] = useState("");
const [sendgrid, setSendgrid] = useState("");
const globalConfig = useGlobalConfig();
function save() {
globalConfig.setAsync(
["template_variables", table.name, field.id],
sendgrid
);
setField("");
setSendgrid("");
setIsDialogOpen(false);
}
return (
<>
<Button onClick={() => setIsDialogOpen(true)}>
Add new template variable
</Button>
{isDialogOpen && (
<Dialog onClose={() => setIsDialogOpen(false)} width="320px">
<Dialog.CloseButton />
<FormField
label="Airtable field"
description="What field contains the data you want to send to sendgrid?"
>
<FieldPicker
table={table}
field={field}
onChange={(newField) => setField(newField)}
/>
</FormField>
<FormField
label="Sendgrid reference"
description="How does the sengrid template refer to this data?"
>
<Input
value={sendgrid}
onChange={(e) => setSendgrid(e.target.value)}
/>
</FormField>
<Button onClick={save}>Save</Button>
</Dialog>
)}
</>
);
}
Example #11
Source File: index.js From blocks-usa-map with MIT License | 4 votes |
function USAMapBlock() {
const [isShowingSettings, setIsShowingSettings] = useState(false);
const [selectedState, setSelectedState] = useState(null);
useSettingsButton(function() {
setIsShowingSettings(!isShowingSettings);
});
const viewport = useViewport();
const base = useBase();
const globalConfig = useGlobalConfig();
const tableId = globalConfig.get('selectedTableId');
const stateFieldId = globalConfig.get('selectedStateFieldId');
const colorFieldId = globalConfig.get('selectedColorFieldId');
const table = base.getTableByIdIfExists(tableId);
const stateField = table ? table.getFieldByIdIfExists(stateFieldId) : null;
const colorField = table ? table.getFieldByIdIfExists(colorFieldId) : null;
// if (table == null || stateField == null || colorField == null) {
// setIsShowingSettings(true);
// }
const records = useRecords(stateField ? table : null);
let mapData = null;
if (stateField !== null && colorField !== null) {
mapData = getMapData(records, stateField, colorField);
}
const mapHandler = (event) => {
setSelectedState(event.target.dataset.name);
};
// If settings is showing, draw settings only
if (isShowingSettings) {
return (
<Box padding={3} display="flex">
<FormField
label="Table"
description="Choose the table you want to your State data to come from."
padding={1}
marginBottom={0}
>
<TablePickerSynced globalConfigKey="selectedTableId" />
</FormField>
<FormField
label="State Field"
description='The State field will select a state by either abbreviation ("NJ") or name ("New Jersey")'
marginBottom={0}
padding={1}
>
<FieldPickerSynced
table={table}
globalConfigKey="selectedStateFieldId"
placeholder="Pick a 'state' field..."
allowedTypes={[FieldType.SINGLE_LINE_TEXT, FieldType.SINGLE_SELECT, FieldType.MULTIPLE_RECORD_LINKS, FieldType.MULTIPLE_LOOKUP_VALUES]}
/>
</FormField>
<FormField
label="Color Field"
marginBottom={0}
description="Choose the state color using either a text field which describes the color name, or a single select."
padding={1}
>
<FieldPickerSynced
table={table}
globalConfigKey="selectedColorFieldId"
placeholder="Pick a 'color' field..."
allowedTypes={[FieldType.SINGLE_LINE_TEXT, FieldType.SINGLE_SELECT, FieldType.MULTIPLE_LOOKUP_VALUES, FieldType.NUMBER]}
/>
{colorField != null && colorField.type === FieldType.NUMBER &&
<text>You have selected a numeric type; state colors will be normalized to the maximum value in your field.</text>
}
</FormField>
</Box>
)
}
// otherwise draw the map.
return (
<div>
<Box border="default"
backgroundColor="lightGray1"
// padding={}
>
{/* TODO Allow selected state to show a column of data. */}
{/* {selectedState
? <SelectedState selected={selectedState}/>
: <div>Click to select a state</div>
} */}
<USAMap
title="USA USA USA"
width={viewport.size.width}
height={viewport.size.height - 5}
customize={mapData}
onClick={mapHandler}
/>
</Box>
</div>
)
}