HEX
Server: Apache/2
System: Linux host.jethost.pl 4.19.0-26-amd64 #1 SMP Debian 4.19.304-1 (2024-01-09) x86_64
User: frigodor (1049)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname,mail
Upload Files
File: /home/frigodor/public_html/wp-content/themes/Divi/common/stories/controls/categories.stories.js
// External dependencies.
import React, { useState } from 'react';

// Internal dependencies.
import CommonCategories from '@common-ui/controls/categories/categories';


export default {
  title: 'Controls/Categories',
  component: CommonCategories,
  argTypes: { onCategoriesChange: { action: 'changed' } },
};

const Template = args => {
  const [selectedCategories, setSelectedCategories] = useState(args.selectedCategories);

  const onCategoriesChange = (value, updateType) => {
    args.onCategoriesChange(value, updateType);

    if (updateType === 'add') {
      setSelectedCategories([...selectedCategories, value]);
    } else {
      setSelectedCategories(selectedCategories.filter(category => category !== value));
    }
  };

  return <CommonCategories {...args} selectedCategories={selectedCategories} onCategoriesChange={onCategoriesChange} />;
};

export const Default = args => <Template {...args} />;
Default.args = {
  selectedCategories: [],
  allCategories: {1: 'Category 1', 2: 'Category 2', 3: 'Category 3'},
  disabled: false,
  markedCategories: [],
  categoryMark: '',
};

export const WithSelectedCategories = args => <Template {...args} />;
WithSelectedCategories.args = {
  ...Default.args,
  selectedCategories: [1, 3],
};

export const WithMarkedCategories = args => <Template {...args} />;
WithMarkedCategories.args = {
  ...Default.args,
  markedCategories: ['Category 1'],
  categoryMark: '*',
};

export const Disabled = args => <Template {...args} />;
Disabled.args = {
  ...Default.args,
  disabled: true,
};