UNPKG

@looker/embed-components

Version:
52 lines 1.36 kB
import React, { useEffect, useState } from 'react'; import { Select, SpaceVertical, ValidationMessage } from '@looker/components'; import { useThemeActions, useThemesStoreState } from './state'; export var SelectTheme = () => { var { initialized, themes, selectedTheme, error, working } = useThemesStoreState(); var { initAction, loadThemeDataAction, selectThemeAction } = useThemeActions(); var [options, setOptions] = useState([]); useEffect(() => { initAction(); }, []); useEffect(() => { if (initialized) { loadThemeDataAction(); } }, [initialized]); useEffect(() => { var themeOptions = themes.map(theme => ({ value: theme.id, label: theme.name })).sort((x, y) => x.label.localeCompare(y.label)); setOptions(themeOptions); }, [themes]); var handleChange = key => { selectThemeAction({ key }); }; return React.createElement(SpaceVertical, { gap: "xxxsmall" }, React.createElement(Select, { disabled: themes.length <= 1, isLoading: !initialized || working, validationType: error ? 'error' : undefined, value: selectedTheme.name, options: options, onChange: handleChange }), error && React.createElement(ValidationMessage, { type: "error", message: error })); }; //# sourceMappingURL=SelectTheme.js.map