Skip to content

🎥 Make videos programmatically with React

combobox

JonnyBurgerbfddcd6c0622
diff --git a/packages/studio/src/components/NewComposition/ComboBox.tsx b/packages/studio/src/components/NewComposition/ComboBox.tsx
index 16706c5d31..a08788a722 100644
--- a/packages/studio/src/components/NewComposition/ComboBox.tsx
+++ b/packages/studio/src/components/NewComposition/ComboBox.tsx
@@ -33,6 +33,11 @@ const container: React.CSSProperties = {
maxWidth: '100%',
};
+const smallContainer: React.CSSProperties = {
+ ...container,
+ padding: '3px 4px',
+};
+
const label: React.CSSProperties = {
flex: 1,
overflow: 'hidden',
@@ -41,6 +46,12 @@ const label: React.CSSProperties = {
textAlign: 'left',
};
+const smallLabel: React.CSSProperties = {
+ ...label,
+ fontSize: 11,
+ lineHeight: 1,
+};
+
type DividerItem = {
type: 'divider';
id: string;
@@ -72,7 +83,8 @@ export const Combobox: React.FC<{
readonly selectedId: string | number;
readonly style?: React.CSSProperties;
readonly title: string;
-}> = ({values, selectedId, style: customStyle, title}) => {
+ readonly small?: boolean;
+}> = ({values, selectedId, style: customStyle, title, small = false}) => {
const [hovered, setIsHovered] = useState(false);
const [opened, setOpened] = useState(false);
const ref = useRef<HTMLButtonElement>(null);
@@ -215,7 +227,7 @@ export const Combobox: React.FC<{
const style = useMemo((): React.CSSProperties => {
return {
- ...container,
+ ...(small ? smallContainer : container),
...(customStyle ?? {}),
userSelect: 'none',
WebkitUserSelect: 'none',
@@ -229,7 +241,7 @@ export const Combobox: React.FC<{
? INPUT_BORDER_COLOR_HOVERED
: INPUT_BORDER_COLOR_UNHOVERED,
};
- }, [customStyle, hovered, opened]);
+ }, [customStyle, hovered, opened, small]);
return (
<>
@@ -246,12 +258,12 @@ export const Combobox: React.FC<{
title={
typeof selected.label === 'string' ? selected.label : undefined
}
- style={label}
+ style={small ? smallLabel : label}
>
{selected?.label}
</div>
) : null}
- <Spacing x={1} /> <CaretDown />
+ <Spacing x={small ? 0.5 : 1} /> <CaretDown small={small} />
</button>
{portalStyle
? ReactDOM.createPortal(
diff --git a/packages/studio/src/components/Timeline/TimelineEnumField.tsx b/packages/studio/src/components/Timeline/TimelineEnumField.tsx
index 167cd3bf88..e6a525b813 100644
--- a/packages/studio/src/components/Timeline/TimelineEnumField.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEnumField.tsx
@@ -1,14 +1,10 @@
-import React, {useCallback} from 'react';
+import React, {useCallback, useMemo} from 'react';
import type {SchemaFieldInfo} from '../../helpers/timeline-layout';
+import type {ComboboxValue} from '../NewComposition/ComboBox';
+import {Combobox} from '../NewComposition/ComboBox';
-const selectStyle: React.CSSProperties = {
+const comboboxStyle: React.CSSProperties = {
marginLeft: 8,
- background: 'transparent',
- color: 'white',
- border: '1px solid rgba(255, 255, 255, 0.2)',
- borderRadius: 3,
- fontSize: 12,
- padding: '1px 4px',
};
export const TimelineEnumField: React.FC<{
@@ -36,9 +32,8 @@ export const TimelineEnumField: React.FC<{
const variantKeys = Object.keys(fieldSchema.variants);
const current = String(effectiveValue ?? fieldSchema.default);
- const onChange = useCallback(
- (e: React.ChangeEvent<HTMLSelectElement>) => {
- const newValue = e.target.value;
+ const onSelect = useCallback(
+ (newValue: string) => {
if (!canUpdate || newValue === codeValue) {
return;
}
@@ -51,18 +46,28 @@ export const TimelineEnumField: React.FC<{
[canUpdate, codeValue, field.key, onSave, onDragValueChange, onDragEnd],
);
+ const items = useMemo<ComboboxValue[]>(() => {
+ return variantKeys.map((key) => ({
+ type: 'item',
+ id: key,
+ value: key,
+ label: key,
+ onClick: () => onSelect(key),
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ quickSwitcherLabel: null,
+ disabled: !canUpdate,
+ }));
+ }, [variantKeys, onSelect, canUpdate]);
+
return (
- <select
- disabled={!canUpdate}
- value={current}
- onChange={onChange}
- style={selectStyle}
- >
- {variantKeys.map((key) => (
- <option key={key} value={key}>
- {key}
- </option>
- ))}
- </select>
+ <Combobox
+ small
+ title={field.key}
+ selectedId={current}
+ values={items}
+ style={comboboxStyle}
+ />
);
};
diff --git a/packages/studio/src/components/Timeline/TimelineSchemaField.tsx b/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
index 82b7a514ce..2116bc432c 100644
--- a/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
@@ -19,6 +19,10 @@ const notEditableBackground: React.CSSProperties = {
padding: '0 4px',
};
+const inlineWrapper: React.CSSProperties = {
+ fontSize: 12,
+};
+
export const TimelineFieldValue: React.FC<{
readonly field: SchemaFieldInfo;
readonly onSave: (key: string, value: unknown) => Promise<void>;
@@ -129,7 +133,7 @@ export const TimelineFieldValue: React.FC<{
if (field.typeName === 'enum') {
return (
- <span style={wrapperStyle}>
+ <span style={inlineWrapper}>
<TimelineEnumField
field={field}
codeValue={codeValue}
diff --git a/packages/studio/src/icons/caret.tsx b/packages/studio/src/icons/caret.tsx
index 4815153c79..4f1e25361a 100644
--- a/packages/studio/src/icons/caret.tsx
+++ b/packages/studio/src/icons/caret.tsx
@@ -9,6 +9,10 @@ const caretDown: React.CSSProperties = {
width: 10,
};
+const caretDownSmall: React.CSSProperties = {
+ width: 7,
+};
+
const angleDown: React.CSSProperties = {
width: 10,
};
@@ -22,9 +26,11 @@ export const CaretRight = () => (
</svg>
);
-export const CaretDown = () => {
+export const CaretDown: React.FC<{readonly small?: boolean}> = ({
+ small = false,
+}) => {
return (
- <svg viewBox="0 0 320 512" style={caretDown}>
+ <svg viewBox="0 0 320 512" style={small ? caretDownSmall : caretDown}>
<path
fill="currentColor"
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"