Skip to content
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
2 changes: 1 addition & 1 deletion src/components/previews/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const Preview = <TProps,>({
if (typeof value === 'number') {
return `{${value}}`;
}
if (value === null || value === undefined) {
if (value === null || value === undefined || (Array.isArray(value) && value.length === 0)) {
return '';
}
return `{${JSON.stringify(value, null, 3)}}`;
Expand Down
7 changes: 2 additions & 5 deletions src/components/previews/properties/SelectOptionsProperty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { KolButton, KolCard, KolDrawer, KolInputCheckbox, KolInputText } from '@
import { translate } from '@docusaurus/Translate';
import React, { useEffect, useState } from 'react';
import type { Option } from '@public-ui/components';
import { SelectOptionsDefault } from './ComponentDefaults';

type SelectOptionsPropertyProps = {
label: string;
_value?: Option<string>;
_value?: Option<string>[];
_on?: {
onInput?: (event: Event, value: unknown) => void;
};
Expand All @@ -17,8 +16,6 @@ const createDefaultOption = (label: string): Option<string> => ({
value: `Value ${label}`,
});

const INITIAL_OPTIONS: Option<string>[] = SelectOptionsDefault;

type UpdateFn = (updater: (option: Option<string>) => Option<string>) => void;
type RemoveFn = () => void;

Expand Down Expand Up @@ -81,7 +78,7 @@ const SelectOptionEditor: React.FC<{

const SelectOptionsProperty = (props: SelectOptionsPropertyProps) => {
const [isEditing, setIsEditing] = useState(false);
const [options, setOptions] = useState<Option<string>[]>(INITIAL_OPTIONS);
const [options, setOptions] = useState<Option<string>[]>(props._value ?? []);

useEffect(() => {
props._on?.onInput?.(new Event('input'), options);
Expand Down
5 changes: 1 addition & 4 deletions src/components/previews/properties/SuggestionsProperty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { KolButton, KolCard, KolDrawer, KolInputText } from '@public-ui/react-v1
import { translate } from '@docusaurus/Translate';
import React, { useEffect, useState } from 'react';
import type { W3CInputValue } from '@public-ui/components';
import { ComboboxSuggestionsDefault } from './ComponentDefaults';

type SuggestionsPropertyProps = {
label: string;
Expand All @@ -27,8 +26,6 @@ const toW3CInputValue = (input: string): W3CInputValue => {

const createDefaultSuggestion = (label: string): W3CInputValue => label;

const INITIAL_SUGGESTIONS: W3CInputValue[] = ComboboxSuggestionsDefault;

type UpdateFn = (updater: (suggestion: W3CInputValue) => W3CInputValue) => void;
type RemoveFn = () => void;

Expand Down Expand Up @@ -72,7 +69,7 @@ const ComboboxSuggestionsEditor: React.FC<{

const SuggestionsProperty = (props: SuggestionsPropertyProps) => {
const [isEditing, setIsEditing] = useState(false);
const [suggestions, setSuggestions] = useState<W3CInputValue[]>(INITIAL_SUGGESTIONS);
const [suggestions, setSuggestions] = useState<W3CInputValue[]>(props._value ?? []);

useEffect(() => {
props._on?.onInput?.(new Event('input'), suggestions);
Expand Down
Loading