@grafana/data#getColorName TypeScript Examples

The following examples show how to use @grafana/data#getColorName. 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: ColorPickerPopover.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
renderPicker = () => {
    const { activePicker } = this.state;
    const { color, theme } = this.props;

    switch (activePicker) {
      case 'spectrum':
        return <SpectrumPalette color={color} onChange={this.handleChange} theme={theme} />;
      case 'palette':
        return (
          <NamedColorsPalette color={getColorName(color, theme.type)} onChange={this.handleChange} theme={theme} />
        );
      default:
        return this.renderCustomPicker(activePicker);
    }
  };
Example #2
Source File: NamedColorsPalette.story.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
NamedColorsPaletteStories.add('Named colors swatch - support for named colors', () => {
  const selectedColor = select(
    'Selected color',
    {
      Green: 'green',
      Red: 'red',
      'Light blue': 'light-blue',
    },
    'red'
  );

  return (
    <UseState initialState={selectedColor}>
      {(selectedColor, updateSelectedColor) => {
        return renderComponentWithTheme(NamedColorsPalette, {
          color: selectedColor,
          onChange: updateSelectedColor,
        });
      }}
    </UseState>
  );
}).add('Named colors swatch - support for hex values', () => {
  const selectedColor = select(
    'Selected color',
    {
      Green: BasicGreen.variants.dark,
      Red: BasicRed.variants.dark,
      'Light blue': LightBlue.variants.dark,
    },
    'red'
  );
  return (
    <UseState initialState={selectedColor}>
      {(selectedColor, updateSelectedColor) => {
        return renderComponentWithTheme(NamedColorsPalette, {
          color: getColorName(selectedColor),
          onChange: updateSelectedColor,
        });
      }}
    </UseState>
  );
});