modulz / modulz-original-design-system-archive

An open-source design system for building scalable, responsive websites and applications.
https://www.modulz.co/showcase
MIT License
313 stars 23 forks source link

Implement a dropdown/popover component #2

Open colmtuite opened 7 years ago

colmtuite commented 7 years ago

I've added a rough and basic dropdown component, you can read the docs inside docs/components/context.html, the CSS inside src/components/Context.css and the JS inside docs/js/Context.js.

To see what I have working so far, you can check out the Context component docs page.

As you can see, this component is currently called "Context". The primary reason for this is because "Dropdown" is not really suitable, since sometimes the menu will drop up and other times it will appear to the left or right. So really, this is just a contextual menu which overlays content. A more suitable name might be "Popover". I'd love to hear any suggestions on this.

That brings me to the main design question I'm thinking about regarding this component - should this component handle all contextual overlays? I'm leaning toward "yes".

In many apps you will see typical dropdown components in top app bars for example, or expanding when you click an icon. You will also see hovercard components, for example on Twitter or Facebook when you hover a username, a popover appears after a brief delay. Many apps also have context menus which appear when you right-click. From a visual design perspective, each of these components are exactly identical. There is not a single style that differs between them. This leads me to think that they should all be the same component.

If we have just one component, we can allow various options for trigger, delay, position etc. If we separate them into 3 or 4 different components, I imagine much of the code will be duplicated - certainly all of the CSS will be duplicated. So, I'm leaning toward having just one component. I'd very much like feedback on this too.

So, assuming we have just one component for all scenarios, here's how I imagine it should behave by default:

Trigger

Direction

Position

Delay

When trigger="hover" is set, a delay option should be provided which will delay opening the Context panel until a certain time period has passed. The delay value should be set in milliseconds. The delay should only affect the opening of the Context panel, closing should happen instantly. I think we should restrict this option to when trigger="hover" is set, though I'm not sure about that. Any feedback much appreciated.

General

asvny commented 7 years ago

Hey .. thanks for detailed writeup !

Let me start and get back to you ... when I have a working one !

asvny commented 7 years ago

@colmtuite I think you might have come across http://mdo.github.io/mdoml I ❤️ mdoml

your thoughts ?

colmtuite commented 7 years ago

I've used o- and c- prefixes a lot in the past but I've stopped using them because they don't provide any benefits to me anymore. My utility classes follow a strict kebab-case naming pattern e.g. display-block and my components are PascalCase e.g. StatusIndicator. So it's very easy to tell the difference between the two without any issues. There are never any conflicts either.

I'm fine with data-attributes if you think that's a good option. I think initialising with JS would require a separate script for each Context instance, which I imagine would become verbose? In my mind, the customisation of each Context component is specific to the view, so I'm fine with that customisation happening in the view. I'm not at all concerned with bloated markup. Browsers don't have any issues with it, so neither do I.

Thanks for getting involved with this, I'm excited to see what you come up with!

I have seen mdoml yes. I appreciate what he is experimenting with and I think there are some pros. Ultimately, I just don't think it has a significant benefit to a large project. A lot of the HTML elements have some semantic or functional value e.g. h1, h2, h3, p, span, a, form, button, header etc. The majority of components are covered by these semantic tags and I just don't think there are that many components leftover that could benefit from a custom tag. I enjoy the simplicity that React provides by abstracting the classes out of the view into a custom tag but I think this is better suited to a library like React which renders valid markup.

colmtuite commented 7 years ago

I thought of a detail I left out of the original spec above.

As per the spec above, when its direction attribute is set to either direction="vertical" or direction="horizontal", or when its position attribute is set to position="center", the Context panel should adapt its direction and position if it extends beyond the boundaries of the viewport/window.

However, I forgot to mention, sometimes it can be necessary to have it adapt to a specific parent element .e.g in a Context component inside a scrolling comment feed, you might want the Context panel to open downward by default, except when you reach the bottom of the comment feed, then open upward.

Again, I'm not sure how this should work. Pass the ID of the relative element in a data-attribute? Also, this can be tackled further down the line, after we get something working.

asvny commented 7 years ago

I am closer ... I will share the link soon !

colmtuite commented 7 years ago

Have you seen https://popper.js.org/? It could help us a lot with this component.

Also, we have a rough demo of a first attempt at this component in our Slack channel. If you want to join, send me your email and I'll invite you.