Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIAi2 WildChat-4.8M (AI2)

import React, { useState } from 'react'; import { FwButton, FwIcon, FwListOptions,…

  1. User

    import React, { useState } from 'react'; import { FwButton, FwIcon, FwListOptions, FwPopover, } from '@freshworks/crayons/react';

    const Popover = () => { var sortByData = [ { value: '1', text: 'Premier Accounts', graphicsProps: { name: 'verified' }, }, { value: '2', text: 'Expired Accounts', graphicsProps: { name: 'alert' }, }, { value: '3', text: 'Freshconect Accounts', graphicsProps: { name: 'freshconnect' }, }, { value: '4', text: 'Freshchat Accounts', graphicsProps: { name: 'freshchat' }, }, { value: '5', text: 'Verified Accounts', graphicsProps: { name: 'ticket-primary' }, }, ]; var sortOrderData = [ { value: 'vertical-align-bottom', text: 'Ascending', graphicsProps: { name: 'vertical-align-bottom' }, }, { value: 'vertical-align-top', text: 'Descending', graphicsProps: { name: 'vertical-align-top' }, }, ];

    // Setting initial states const [sortBy, setSortBy] = useState(sortByData[0]); const [sortOrder, setSortOrder] = useState(sortOrderData[0]);

    const onSortChange = (event) => { setSortBy(event.detail?.meta?.selectedOptions[0]); };

    const onSortOrderChange = (event) => { setSortOrder(event.detail?.meta?.selectedOptions[0]); };

    return ( {sortBy.text} <span style={{ fontStyle: 'italic' }} className='row fw-flex fw-type-xs fw-p-4 fw-type-semibold' > Sort Customers By <hr style={{ margin: '0px' }} />

          <span
            style={{ fontStyle: 'italic' }}
            className='row fw-flex fw-type-xs fw-p-4 fw-type-semibold'
          >
            Sort Order
          </span>
          <hr style={{ margin: '0px' }} />
          <FwListOptions
            onFwChange={onSortOrderChange}
            selectedOptions={[sortOrderData[0]]}
            options={sortOrderData}
            variant='icon'
          ></FwListOptions>
        </div>
      </FwPopover>
    </div>
    

    ); };

    export default Popover;

    in this popover keep All Rules and Duplicate Rules alone.

  2. Assistant

    It looks like you have a popover component with two lists (sortByData and sortOrderData) and you want to modify it to keep only "All Rules" and "Duplicate Rules" in one of these lists. However, in your provided data arrays (sortByData and sortOrderData), I don't see "All Rules" or "Duplicate Rules." So I assume:

    • You want to replace the current options with just "All Rules" and "Duplicate Rules" and keep the popover structure the same.
    • Possibly keep two lists or only the relevant one showing those two options.

    How I interpret your request

    • You want a popover with options limited to just "All Rules" and "Duplicate Rules".
    • I will create a new data array (or modify existing) so that the popover options show only those two.
    • Keep the rest of the component the same, just updating the data and initial state.

    Modified Code

    import React, { useState } from 'react';
    import {
      FwButton,
      FwIcon,
      FwListOptions,
      FwPopover,
    } from '@freshworks/crayons/react';
    
    const Popover = () => {
      // Only the two options you want to keep
      var rulesData = [
        {
          value: 'all_rules',
          text: 'All Rules',
          graphicsProps: { name: 'list' },  // you can change the icon
        },
        {
          value: 'duplicate_rules',
          text: 'Duplicate Rules',
          graphicsProps: { name: 'alert' }, // choice of icon
        },
      ];
    
      // Initial state for selected rule
      const [selectedRule, setSelectedRule] = useState(rulesData[0]);
    
      const onRuleChange = (event) => {
        setSelectedRule(event.detail?.meta?.selectedOptions[0]);
      };
    
      return (
        <div>
          <FwPopover sameWidth='false' placement='bottom-start'>
            <FwButton slot='popover-trigger' color='secondary' showCaretIcon>
              <FwIcon slot='before-label' name={selectedRule.graphicsProps.name}></FwIcon>
              <span id='buttonContent'>{selectedRule.text}</span>
            </FwButton>
    
            <div slot='popover-content'>
              <span
                style={{ fontStyle: 'italic' }}
                className='row fw-flex fw-type-xs fw-p-4 fw-type-semibold'
              >
                Choose Rule
              </span>
              <hr style={{ margin: '0px' }} />
              <FwListOptions
                onFwChange={onRuleChange}
                selectedOptions={[selectedRule]}
                options={rulesData}
                variant='icon'
              />
            </div>
          </FwPopover>
        </div>
      );
    };
    
    export default Popover;
    

    Explanation

    • Created a single array rulesData with only "All Rules" and "Duplicate Rules".
    • Used one list (FwListOptions) instead of two.
    • Initialized state with first option.
    • Updated handlers and props accordingly.
    • Changed icon names to match meaningful icons (list and alert can be updated to any available icons you prefer).

    If you want to keep both Sort By and Sort Order lists but only with All Rules and Duplicate Rules in one list and keep the other as it is, please clarify.

    Otherwise, this is how you keep only the specified rules in the popover options.