nicedouble / StreamlitAntdComponents

A Streamlit component to display Antd-Design
https://nicedouble-streamlitantdcomponentsdemo-app-middmy.streamlit.app/
MIT License
440 stars 29 forks source link

"On hover" parameter for expanding options in the sac.cascade component #56

Open mkleinbort-ic opened 6 months ago

mkleinbort-ic commented 6 months ago

The ant "cascade" suports expanding the options on hover, but I don't think this is currently possible in the sac.cascade component.

image

The relevant code from ant is the expandTrigger as seen here:

import React from 'react';
import type { CascaderProps } from 'antd';
import { Cascader } from 'antd';

interface Option {
  value: string;
  label: string;
  children?: Option[];
}

const options: Option[] = [
  {
    value: 'zhejiang',
    label: 'Zhejiang',
    children: [
      {
        value: 'hangzhou',
        label: 'Hangzhou',
        children: [
          {
            value: 'xihu',
            label: 'West Lake',
          },
        ],
      },
    ],
  },
  {
    value: 'jiangsu',
    label: 'Jiangsu',
    children: [
      {
        value: 'nanjing',
        label: 'Nanjing',
        children: [
          {
            value: 'zhonghuamen',
            label: 'Zhong Hua Men',
          },
        ],
      },
    ],
  },
];

const onChange: CascaderProps<Option>['onChange'] = (value) => {
  console.log(value);
};

// Just show the latest item.
const displayRender = (labels: string[]) => labels[labels.length - 1];

const App: React.FC = () => (
  <Cascader
    options={options}
    expandTrigger="hover" // <---------------------- HERE
    displayRender={displayRender}
    onChange={onChange}
  />
);

export default App;