Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close button style doesn't match example / no way to modify with props #153

Open
chriskonopka opened this issue Jul 30, 2020 · 0 comments
Open

Comments

@chriskonopka
Copy link

Using the complicated example I'm looking to create draggable and closable tabs.
While having succeded in doing this, the close button appears to always have a gray square background.
Screen Shot 2020-07-30 at 4 21 44 PM

Looking through the code, it seems that the CloseButton cannot be modified by passing props into the tab component so I'm not sure how to fix besides coping the codebase and making the tweaks myself.

would like a way to modify the close button via props or a fix to the gray square appearing in my example.

including my example file below in case I am missing something:

const makeData = (number, titlePrefix = 'Tab') => {
  const data = [];
  for (let i = 0; i < number; i++) {
    data.push({
      title: `${titlePrefix} ${i}`,
      content:
        <div>
          Content {i}: Accusamus enim nisi itaque voluptas nesciunt repudiandae velit. <br/>
          Ad molestiae magni quidem saepe et quia voluptatibus minima. <br/>
          Omnis autem distinctio tempore. Qui omnis eum illum adipisci ab. <br/>
        </div>
    });
  }
  return data;
}

class tabView extends React.PureComponent {
  constructor(props) {
    super(props);
    this.handleTabChange = this.handleTabChange.bind(this);
    this.handleTabSequenceChange = this.handleTabSequenceChange.bind(this);
    const tabs = makeData(3, 'DragTab');
    this.state = {
      activeIndex: 0,
      tabs
    }
  }

  handleEdit = ({type, index}) => {
    this.setState((state) => {
      let {tabs, activeIndex} = state;
      if (type === 'delete') {
        tabs = [...tabs.slice(0, index), ...tabs.slice(index + 1)];
      }
      if (index - 1 >= 0) {
        activeIndex = index - 1;
      } else {
        activeIndex = 0;
      }
      return {tabs, activeIndex};
    });
  }

  handleTabChange(index) {
    this.setState({activeIndex: index});
  }

  handleTabSequenceChange({oldIndex, newIndex}) {
    const {tabs} = this.state;
    const updateTabs = simpleSwitch(tabs, oldIndex, newIndex);
    this.setState({tabs: updateTabs, activeIndex: newIndex});
  }

  render() {
    const {tabs, activeIndex} = this.state;
    const tabsTemplate = [];
    const panelTemplate = [];
    tabs.forEach((tab, index) => {
      const closable = tabs.length > 1;
      tabsTemplate.push(<DragTab key={index} closable={closable}>{tab.title}</DragTab>)
      panelTemplate.push(<Panel key={index}>{tab.content}</Panel>)
    })
    return (
      <Tabs activeIndex={activeIndex}
            onTabEdit={this.handleEdit}
            onTabChange={this.handleTabChange}
            onTabSequenceChange={this.handleTabSequenceChange}
            customStyle={themes["bootstrap"].style}
            >
        <DragTabList>
          {tabsTemplate}
        </DragTabList>
        <PanelList>
          {panelTemplate}
        </PanelList>
      </Tabs>
    )
  }
}
export default tabView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant