Git Product home page Git Product logo

cucumber-components's Introduction

Cucumber Components Logo

A collection of native web components built on top of web standards with a focus on:

    ๐Ÿšน Accessibility ๐Ÿ— Easy to use ๐ŸŽจ Easy to style

Inspired by https://github.com/thepassle/generic-components

This project started out as Breeze Components, then it was renamed to Cucumber Components on Sep 4, 2023. Logo was designed by me with Inkscape based on cucumber icons ideas from https://www.flaticon.com/free-icons/cucumber, logo font is Input Mono. Reason for renaming is writing cc-button is a bit easier than breeze-button.

Why build a Web Components collection when there are many battle-tested Web Components collections already?

  • A project to dive deep into web accessibility.
  • Helps develop a mindset from both component author and component consumer.
  • A learning experience and an opportunity to gain a deeper understanding of web components best practices.
  • It's fun as you're writing HTML/CSS/JavaScript!

Why go with vanilla Web Components?

  • Vanilla Web Components can take you all the way if you're just building components collection to be consumed by other projects.
  • A better way to play around web components specs and trying out new ideas.
  • Provide a low barrier for entry, making it easier for developers to contribute to component collections.
  • Minimize the bundled size of each component.
  • "The beauty of zero-dependencies!" (#UseThePlatform).

How to contribute

1. Fork and Clone This Repo.

git clone https://github.com/heybran/cucumber-components.git

2. Install dev dependencies

Web Components dev dependencies

npm install

Docs dependencies

cd docs && npm install

3. Creat a component folder at ./src/components.

Structure:

โ”€โ”€ password-field
   โ”œโ”€โ”€ password-field.css
   โ”œโ”€โ”€ password-field.html
   โ””โ”€โ”€ password-field.js

4. Add new component to DOCS ./docs/src/components/demo/ComponentPreview.svelte. This is to import the components codes to render them on the documentation.

const components = [
  'button',
  'icon',
  'option',
  'select',
  'spinner',
  'switch',
  'text-field',
  'textarea',
  'tooltip',
  'form-layout',
  'password-field',
  // new component folder name here
];

5. Create new component documentation page at ./docs/src/pages/components/new-component.md. (If new component folder name is 'new-component').

6. Add sidebar link at ./docs/src/config.ts.

e.g.

export const SIDEBAR = [
  { text: "Alert", link: "/components/alert" },
  { text: "Button", link: "/components/button" },
  { text: "Tooltip", link: "/components/tooltip" },
  { text: "Text Field", link: "/components/text-field" },
  { text: "Select", link: "/components/select" },
  { text: "Switch", link: "/components/switch" },
  { text: "Textarea", link: "/components/textarea" },
  { text: "Spinner", link: "/components/spinner" },
  // new component item here
];

7. Run DOCS dev server and visit http://localhost:3000/

At the moment, all testing are done manually on the components you add to the documentation page.

cd docs && npm run dev

cucumber-components's People

Contributors

heybran avatar lonelyfellas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lonelyfellas

cucumber-components's Issues

A11y: Ensures buttons have discernible text

button element needs a aria-hidden=true when cc-side-nav component does not have toggle behavior.

Element Location: cc-header,cc-side-nav,button[aria-controls="children"]
<button part="label" aria-controls="children">
  <slot name="label"></slot>
  <span part="toggle-icon" aria-hidden="true">
    <cc-icon icon="chevron-down"></cc-icon>
  </span>
</button>

Enhancement: show an warning when `trigger` slot is not provided

popover-wrapper.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'addEventListener')
    at t.connectedCallback (popover-wrapper.js:2:155)
    at Header.render (header.js?t=1701399706555:13:31)
    at Header.connectedCallback (header.js?t=1701399706555:8:10)
    at CucumberRouter._onChanged (index.js:118:17)
    at CucumberRouter.start (index.js:62:10)
    at main.js?t=1701399706555:139:8

this.trigger.addEventListener("click",this.handleTriggerClick.bind(this))

Feat: add a getSlot() helper function to simplify things

Add a getSlot() helper function to reduce boilerplate codes, something like:

attributeChangedCallback(attr, oldValue, newValue) {
  if (attr === 'label') {
    this.shadowRoot.querySelector('slot[name="title"]').textContent = this.getAttribute('label');
  }
}
this.getSlot('title').doSomething();

or

this.slots('title').doSomething();

Bug: cc-date-picker custom calendar button not working on Safari

If visit https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date on safari (Version 16.4 (18615.1.26.110.1)), it does not render a user agent calendar icon like Chrome where you can click to open the date picker modal. As a result, the cc-button to open date picker modal is not working on Safari.

  <div part="input-container">
    <slot name="prefix"></slot>
    <input id="input" part="input" type="date" aria-describedby="helper-text">
    <slot name="suffix">
      <cc-button 
        slot="suffix" 
        theme="square borderless"
        onclick="this.getRootNode().host.showPicker();"
      >
        <cc-icon label="Show date picker" icon="calendar"></cc-icon>
      </cc-button>
    </slot>
  </div>

Even if it's working, the date picker modal on Safari is soooo tiny, now I understand why I always see JavaScript date picker on websites.

Screenshot of date picker modal on Safari

Bug: `cc-date-picker` not working as expected

If I submit the form with an invalid date value, e.g. 2023 /yy/dd with only year populated, component shows native validation error to user which is correct. But, after entering correct date value, submitting the form still reports error.

Screenshot 2023-11-20 at 17 37 33

Feat: add a afterHide() hook to dialog component

When working on a php side project, I'm opening the same dialog but with different content, would be nice to have a afterHide() so users can add a callback.

   <td>
      <cc-button 
        theme="primary" 
        onclick="showDialog(this, 'Message');"
       >View</cc-button>
       <p hidden><?php echo $item['message']['S'] ?></p>
    </td>
    <script>
      function showDialog(button, label) {
        const p = button.nextElementSibling;
        const dialog = document.querySelector('cc-dialog');
        const message = document.createElement('p');
        message.textContent = p.textContent;
        dialog.setAttribute('label', label);
        dialog.prepend(message);
        dialog.show();
        // dialog.afterHide(() => {
        //   message.remove();
        // });
      }
    </script>
    <cc-dialog>
      <cc-button slot="footer-actions-right">Close</cc-button>
    </cc-dialog>

Bug: missing imports from alert component

Alert component includes cc-button and cc-icon but alert.js file didn't import those two components.

<div part="container" role="alert" aria-hidden="true">
	<div part="icon">
		<slot name="icon"></slot>
	</div>
	<div part="message" aria-live="polite">
		<slot></slot>
	</div>
	<div part="close">
		<cc-button theme="icon" no-border onclick="this.getRootNode().host.hide();">
			<cc-icon icon="cross" size="medium"></cc-icon>
		</cc-button>
	</div>
</div>

Bug: Uncaught TypeError: `form.__cucumberElements` is not iterable

This bug happens when working on Nodejs-web-components-jobs-tracker project. For markup like this, there is no form fields other than the submit button, so form.__cucumberElements is undefined.

<form method="post" onsubmit="deleteJob(event);" id="delete-job-form" data-job-id="rec_cl51trli5o087h9qivtg">
    <h2>
        You are about to delete job of https://example.com/1.
    </h2>
    <cc-button theme="primary" type="submit">Confirm</cc-button>
</form>

A11y: support aria-describedby pointing to elements from light dom

Based on Verification Result dialog from Accessibility Features of Modal Dialog Example, cc-dialog component need to support aria-describedby content that comes from light dom, since cross root aria is not supported yet, trying to copy content from light dom into shadow dom and connect dialog element to the content via aria-describedby attribute?

<cc-dialog label="Address Added" id="address-added-dialog">
    <p accessibile-description>Your address has been added succefully. If you wish to remove it, you can do so from your <a href="#">profile</a>.</p>
    <cc-button slot="footer-actions-right" theme="primary" onclick="this.parentElement.close('close');">Ok</cc-button>
</cc-dialog>

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.