Giter VIP home page Giter VIP logo

Comments (8)

HonzaMikula avatar HonzaMikula commented on August 20, 2024 4

The best would be possible turn off style entirely.

from react-tabs.

darkyen avatar darkyen commented on August 20, 2024

Just a suggestion: Let us pass our own style?

from react-tabs.

rhys-vdw avatar rhys-vdw commented on August 20, 2024

Just a suggestion: Let us pass our own style?

I don't like this option because it still forces the project to depend on js-stylesheet.

The best would be possible turn off style entirely.

This is currently possible @HonzaMikula, as a global here.

Yes. It would be better if js-stylesheet were not a dependency, and the styles could optionally be imported like so:

// These no longer require the styles or `js-stylesheet`...
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';

// ...So we must import ourselves...
import jss from 'js-stylesheet';

// If we didn't import this here, it would not be bundled into the project at all.
import TabStyles from 'react-tabs/styles';

class MyTabs {
  componentDidMount() {
    // Bit of extra work - but that's the point.
    jss(TabStyles);
  }

  render() {
    return (
      <Tabs>
         // blah blah
      </Tabs>
    );
  }
}

Right now this project adds js-styles as a dependency, even though my project doesn't use your styles option!

An alternate implementation would move js-stylesheet to optionalDependencies, and instead of importing it at the top of Tabs.js, it could be moved into here like so:

  componentDidMount() {
    if (useDefaultStyles) {
      // Will fail if *optional* dependency is not included - this responsibility is on the client.
      require('js-stylesheet')(require('../helpers/styles.js')); // eslint-disable-line global-require
    }
  },

But this approach is less optimal because the /helpers/styles.js file will still be bundled by webpack (which detects and replaces require statements).

Also if you wanted to do this in a back compatible way, the main package could export Tabs as a higher order component and have react-tabs/unstyled as the functional part of the component. The default exported Tabs component would be something like this:

import jss from 'js-styles';
import styles from './helper/styles';
import UnstyledTabs from './unstyled/tabs';

export default class Tabs {
  componentDidMount() {
    jss(styles);
  }

  render() {
    return <UnstyledTabs {...this.props} />;
  }
}

Actually that last one is probably the best. Want a PR, @danez? If so, which one?

from react-tabs.

lautarodragan avatar lautarodragan commented on August 20, 2024

It'd be awesome if we could pass a prop useDefaultTyles={false}to disable default styles instead of calling Tabs.setUseDefaultStyles(false) globally. It feels more intuitive.

I think that for this to be possible the default styles would need to be included as inline styles (style={props.useDefaultStyles && defaultStyles}), otherwise one Tabs element set to use default styles would pollute the entire CSS and impact all other Tabs elements in the web app.

I think you could also drop the dependency on jss this way, or at least pave the way.

from react-tabs.

lautarodragan avatar lautarodragan commented on August 20, 2024

@danez how did you resolve this in the end? I'm searching for useDefaultStyles on the diff of #161 and can only find it in the old part of the diff, not the new. Also I see you deleted helpers/styles.js entirely.

from react-tabs.

danez avatar danez commented on August 20, 2024

The idea is to not force anyone to use a specific css technology. So instead of having style injected by default with js-stylesheets, react-tabs does not do anything by default regarding css (besides adding classnames to the rendered elements). It is up to the user to wire things up. There is a new file style/react-tabs.css which can be for example imported when using webpack css-loader

import 'react-tabs/style/react-tabs.css';

Or it can be simply copied.
I can maybe also add a sass/less variant that can be imported in someones own sass/less files.

It is a little bit more work to initially get the default style going, but a lot of people wanted to disable the default style (with js-stylesheet) anyway.

Does that sound reasonable? What do you think?

from react-tabs.

WickyNilliams avatar WickyNilliams commented on August 20, 2024

Sounds like the right solution to me 👍

from react-tabs.

lautarodragan avatar lautarodragan commented on August 20, 2024

Yep, sounds perfect to me!

from react-tabs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.