aurelia-toolbelt / vNext

The vNext of Aurelia-Toolbelt which is on top of Aurelia 2.
1 stars 0 forks source link

Final candidates #4

Open HamedFathi opened 4 years ago

HamedFathi commented 4 years ago

Recipes

adoptedStyleSheets is the starting point.

import template from './my-component.html';
import css from './my-component.css';
@customElement({ name: 'my-component', template, dependencies: [shadowCSS(css)] })
export class MyComponent {}

shadowCSS() turns the CSS into a registerable dependency. To register it globally, you can register StyleConfiguration.shadowDOM({ sharedStyles: [css] }) in your app startup and that's also how you could expose CSS as a registerable plugin <use-shadow-dom> and @useShadowDOM is only needed for a CE don't want to follow a global setting. For app/plugin, you can just rely on the global shadowdom setting in your webpack config or gulpfile. When your plugin is built, the information (use shadow dom) is baked into every CE. So that your plugin will always use shadowdom regardless of the user app (which uses your plugin) global setting. The user app might turn off shadow dom, but that only affects the user local code. The CE from your plugin will still use shadow-dom.

/ my-app.js / export class MyApp { @bindable themeColor = getComputedStyle(document.documentElement).getPropertyValue('--theme-color').trim(); themeColorChanged() { document.documentElement.style.setProperty('--theme-color', this.themeColor); } }

/ my-app.css / :host { color: var(--theme-color); }

- [ ] Use Aurelia DI to support plugin-based components. (e.g. set our configs (such as `IRippleEffectConfiguration`) via DI.)
```js
.register(
  AwesomePasswordField.withPlugins(PasswordStrengthChecker, ...)
)

export class LoginPage {
  static get dependencies() { return [AwesomePasswordField.withPlugins(PasswordStrengthChecker, ...)]; }
}

Now, Any tracing-capable bundler can see that registration is either used or not used, and tree-shake it if need be, sample

We use this pattern a lot in v1.

@bindable({ defaultBindingMode: bindingMode.oneWay }) public navigator: boolean | string = false;

this.showNavigator = (this.navigator === '' && this.carouselTemplate.hasAttribute('navigator')) 
                                    || this.navigator.toString() === 'true';

To support the existing tag with or without value

<at-carousel navigator.bind="true">

<at-carousel navigator="true">

<at-carousel navigator=true>

<at-carousel navigator>

Now we can change it a little:

function hasCustomAttribute(htmlElement: HTMLElement, prop: object): boolean {
  const [k, v] = Object.entries(prop)[0];
  const isBoolean =
    v === true ||
    v === false ||
    Object.prototype.toString.call(v) === "[object Boolean]";
  const isString = Object.prototype.toString.call(v) === "[object String]";
  if (!isBoolean && !isString) {
    throw "Custom attribute's type must be one of 'boolean' or 'string'.";
  } else {
    return (v === "" && htmlElement.hasAttribute(k)) || v.toString() === "true";
  }
}

class Carousel {
  navigator: boolean | string = false;
  afterAttach() {
    const hasNavigator = hasCustomAttribute(element, { navigator: this.navigator } /* Key:Value is better that have the same name.  */);
  }
}

Or use the new set feature.

You can change from

<my-component counter.bind="0">

to:

@bindable({ set: Number }) counter

and simplified HTML

<my-component counter="0">

<el navigator> it means <el navigator="">

@bindable({
  set: v => v === '' || Boolean(v)
})
myBool

it depends on how you want your API, another example is anything is true, except false string; <my-el navigator="false">

then you should have

@bindable({
  set: v => !!v && v !== 'false'
})

An advanced example

function truthyDetector(value: unknown) {
  const isBoolean =
    value === true ||
    value === false ||
    Object.prototype.toString.call(value) === "[object Boolean]";
  const isString = Object.prototype.toString.call(value) === "[object String]";
  if (!isBoolean && !isString) {
    throw "The custom attribute's type must be one of 'boolean' or 'string'.";
  } else {
    switch (value) {
      case 'true': return true;
      case 'false': return false;
      // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
      default: return !!value;
    }
  }
}

@bindable({
    // set: v=> truthyDetector(v),
    set: v => {
      switch (v) {
        case 'true': return true;
        case 'false': return false;
        // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
        default: return !!v;
      }
    },
    mode: BindingMode.oneTime
  })
  public fallThrough: boolean = false;

core

The general functionalities that we need during the project and of course can be used separately in other projects will be available in this package.

Ripple

Apply the ripple effect to HTML elements.

applyRippleEffect()

Scroll

Helps us to control scroll bars.

ScrollUp()/ScrollBottom()

bootstrap-v5-core

The whole config files that are related to Bootstrap v5 are here.

Just like variant and so on.

export enum Variant {
    Primary = 'primary',
    Secondary = 'secondary',
    Success = 'success',
    Danger = 'danger',
    Warning = 'warning',
    Info = 'info',
    Light = 'light',
    Dark = 'dark'
}

bootstrap-v5

All native Bootstrap v5 components (sometimes with more features) will be included in this package.

Accordion

at-accordion

With support Multilevel Accordion Menu

Alert

at-alert

With Count down support.

Aspect

at-aspect

Avatar

at-avatar

Badge

at-badge

Breadcrumb

at-breadcrumb

Button

at-button

With promise button support.

To feel clicking better you can add this as a config to remove outline when you are clicking.

.btn:active {
  outline: none !important;
  box-shadow: none !important;
}

Button Group

at-buttongroup

Button Toolbar

at-toolbar

With popover support

image

Card

at-card

Carousel

at-carousel

With responsive multi-items support like this

Also, support Vertical

Also, Slick

Screenshot_1

Close button

at-close

Collapse

at-collapse

And also, truncate functionality.

And With collapsible panel

Dropdown

at-dropdown

With hover support.

$(".dropdown-toggle").on("mouseenter", function () {
    // make sure it is not shown:
    if (!$(this).parent().hasClass("show")) {
        $(this).click();
    }
});

$(".btn-group, .dropdown").on("mouseleave", function () {
    // make sure it is shown:
    if ($(this).hasClass("show")){
        $(this).children('.dropdown-toggle').first().click();
    }
});

With tree support.

image

Embed

at-embed

Figures

at-figure

Support Image Hover too.

Float label

Bootstrap v5 supports floating labels but it does not look good with a very big design!

at-float or css mode

There are two different approaches to this. Custom element. (High-order component) Custom attribute.

Form

https://bootstrap-vue.org/docs/components/form

Support icons like this

And also spinners inside an input like this

Form Checkbox

at-checkbox

Form Color

at-color

Form Datalists

at-datalist

Form File

at-file

We should consider bs-custom-file-input too. (Supports drag & drop)

Also support Drop File style.

Form Group

at-form-group

Form Input

at-input

Form Radio

at-radio

Form Range

at-range

Form Select

at-select

Form Switch

at-switch

Form Textarea

at-textarea

Form Validation

https://v5.getbootstrap.com/docs/5.0/forms/validation/

We should support Bootstrap v5 form validation and integrate it with Aurelia 2 validation.

Image

at-image

Input Group

at-inputgroup

Layout and Grid System

https://bootstrap-vue.org/docs/components/layout

Link

https://bootstrap-vue.org/docs/components/link

List group

at-listgroup

It would be great if we support List Filter too.

list

Media

at-media

Modal

at-modal

This package should support a ModalService to make components in the runtime too.

Also, it should support fullscreen, minimize, maximize, and other custom buttons.

Support window.confirm() and window.alert() override settings.

Nav

at-nav

Navbar

at-navbar

With support mega-menu in hover and clickable mode.

And support multi-level menu or multi-dropdown-navbar

Screenshot_1

With also toggle animation

Pagination

at-pagination and at-pagination

With Bootstrap pagination features and abt-pagination

Popover

at-popover

An option to remove Popover arrow,

.popover .arrow {
  display: none;
}

There are two different approaches to this. Custom element. Custom attribute.

Progress

at-progress

We should support the gradient.

/* From #33156d - To #f282bc */
background: -webkit-linear-gradient(left, #33156d 0%, #f282bc 100%) !important;
background: -o-linear-gradient(left, #33156d 0%, #f282bc 100%) !important;
background: linear-gradient(left, #33156d 0%, #f282bc 100%) !important;

Also suport Nanobar (separate component?!) with RTL.

And also vertical mode.

We should be able to provide circular progress bar too. (separate component?!)

OffCanvas

at-sidebar or side-modals

BottomSheet

Use Bootstrap v5 Offcanvas with the below class

/* class="offcanvas offcanvas-bottom show offcanvas-bottomsheet" */
/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .offcanvas-bottomsheet {
        margin: 0 auto !important;
        width: 30%!important;
    }
}

This can be an attribute to convert Sidebar to BottomSheet.

Spinner

at-spinner

Table

at-table

Tabs

at-tab

With support different alignments like bootstrap-tabs-x

image

It would be great if we support scrolling tabs too.

Toasts

at-toast

This package should support a ToastService to make components in the runtime too.

With queue (prevent duplicates), newest on top, RTL, and progress bar support.

Support different positions Top Right, Bottom Right, Bottom Left, Top Left, Top Full Width, Bottom Full Width, Top Center, Bottom Center, Center Center

Tooltip

at-tooltip

An option to remove Tooltip arrow,

.tooltip .arrow {
  display: none;
}

There are two different approaches to this. Custom element. Custom attribute.

Scrollspy

at-scrollspy

There are two different approaches to this. Custom element. Custom attribute.


bootstrap-v5-plus

Complementary and non-native components that are compatible with Bootstrap v5 are included in this package.

DateTimePicker

Use Day.js and Jalali Day.js for dates.

at-datetime

Consider this too

With support date-range like Date Range Picker image

Textbox + Popover can help to design it!

Confirmation

at-confirmation

bootstrap-confirmation.min.js => 8.62 KB

image

Order List

at-orderlist

orderlist

Password Box

at-password or at-password

Support password-meter and delayed password masking and also bootstrap-show-password-toggle

Spinbutton

at-spin

image

Choice

A more complete version of at-select.

at-choice

This works as an input tag (tokenizer) and also as an advanced select.

Should we choose Select2 and the BS5 Theme

select2.min.css => 15.9 KB select2.min.js => 71.5 KB select2.full.min.js => 75 KB select2-bootstrap-5-theme.min.css => 28 KB select2-bootstrap-5-theme.rtl.min.css => 27.9 KB

Jumbotron

at-jumbotron

.jumbotron {
  padding: 4rem 2rem;
  margin-bottom: 2rem;
  background-color: var(--bs-light);
  border-radius: .3rem;
}
<div class="jumbotron m-3">
  <h1 class="display-4">Hello, world!</h1>
  <p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
  <hr class="my-4">
  <p>It uses utility classes for typography and spacing to space content out within the larger container.</p>
  <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
</div>

Overlay

at-overlay

With this project features.

jquery-loading-overlay.min.js => 11.7 KB

Skeleton

at-skeleton

This library does not yet support RTL.

Rating

at-rate

Toggle

An alternative of [at-switch] with a different theme.

at-toggle

Slider

A more complete version of at-range.

at-slider

Timeline

at-timeline

Tour

at-tour

Dropzone

at-dropzone

Should we support this while we have at-file?

Barcode

at-barcode

QR Code

at-qrcode

Switch to qrcode-generator

Cropper

at-crop

Price Table

at-price

Pick List

at-picklist

picklist

Overlay Scrollbars

at-scrollbar

Stepper

at-stepper

Action Button

at-action

ScrollUp

Use scroll functionalities in the core package.

at-scrollup

We need to be able to use multi instances.

Numpad

at-numpad

Textbox + Popover can help to design it!

News Ticker

at-news

With Bootstrap v5 theme support.

News Box

at-newsbox

Convert it (Responsive-jQuery-News-Ticker) to vanilla js with Bootstrap v5 theme support.

PropertyGrid

at-property

This should redesign with Bootstrap 5 and vanilla js.

image

1

Slide Menu

at-slidemenu

Calendar

at-calendar

It supports Persian via fa locale.

Drag & Drop

at-dnd

Comment Box

at-comment

Poll

at-poll with statistics.

Support single and multi choices.

image

QueryBuilder

at-querybuilder

It should rewrite from scratch with Bootstrap 5 and vanilla js + support .NET as a server-side approach.

image


vanilla (A better name?!)

This section covers other components that are not necessarily related to Bootstrap and its theme.

CountUp

at-countup

Knob

at-knob

check pure-knob too.

Chart

at-chart

Photo Zoom

at-zoom

This should convert to vanilla js.

Divider

at-divider

Dom Outline

at-dom

This should redesign with vanilla js.

WYSIWYG Editor

at-htmleditor

Spreadsheet

at-spreadsheet

Splitter

at-split

Syntax Highlighter

at-highlight

Consider this implementation too.

Typed

at-typed

With support RTL direction.

float:right;
text-align:right;
direction: rtl;

custom-attributes

We will add our standalone custom attributes here.

Ripple

at-ripple

In this component we use applyRippleEffect() inside the core package.

There are two different approaches to this. Custom element. (High-order component) Custom attribute.

Input Mask

at-mask

MaxLength

at-maxlength

Sticky

at-sticky

This will support ScrollPos-Styler and also the old Bootstrap Affix.

Lazy

at-lazy


icons

This package should support Bootstrap Icons as a first-class citizen. Finally, we are able to complete it too.

at-icon-*

Also, we support spin kits. (Should be in a separate package?)

at-spin-* like ng-spin-kit


services

We need some services such as:


ts-utils

Here are some useful functions that we use a lot.


persian-ts-utils

Persian utilities that are made by Typescript.

Iranian postal code validation

this is some rules about this regex:
It's all numeric
10 digit count
don't use 0 in the first 5 digit
don't use 2 in postal code
First 4 digit is not the same
The 5th digit cannot be 5
all digits aren't the same

The following regex satisifes your conditions:
\b(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}\b

Explanation:
\b - a word boundary
(?!(\d)\1{3}) - negative lookahead to make sure that the first 4 digits are not the same.
[13-9]{4} - matches 4 occurrences of all the digits except 0 and 2
[1346-9] - matches a single digit that is not a 0,2 or 5
[013-9]{5} - matches 5 occurrences of all the digits except 2
\b - a word boundary

I made ts-persian-toolkit for this purpose.

ts-persian-toolkit.min.js => 6.20 KB


at-dependencies

If we have to depend on third-party JS/TS libraries we collect them in this section.


dashboard

We want to support different pre-defined layout for our users.

We want to design all possible layouts like Metronic + a blog layout


dashboard-cli

A CLI to create a different dashboard immediately.


form-designer

An offline Electron-based application to create Aurelia-Toolbelt application with interactive (drag & drop) designer like Bootstrap Studio

Support Dynamic Form Generator (JSON Schema-based)


demo

We show here everything that has been prepared so far.

Our e2e testing will be based on this package.


Irreplaceable jQuery-based components!

There is no good alternative for these components in vanilla js world! so we have to decide what to do about these.