1.0.2 • Published 4 years ago

@axa-ch/patterns-library v1.0.2

Weekly downloads
716
License
MIT
Repository
github
Last release
4 years ago

Build Status

The AXA CH Style and HTML Guide (Editor's Draft)

Preview can be found here: https://axa-ch.github.io/patterns-library/

This is the core pattern library used for AXA Switzerland. It's based on Web-Components. Web-Components are natively supported in modern browser. This repo contains also polyfills for those less "cool" browsers out there. Support is:

  • ie 11 (Polyfill for template, html import, shadow dom and custom element)
  • EDGE (Polyfill for html import, shadow dom and custom element)
  • FF (Polyfill for html import, shadow dom and custom element)
  • Chrome / Chrome Mobile (100% native)
  • Safari / iOS Safari (Polyfill for html import)

REF: https://github.com/webcomponents/webcomponentsjs

The main goal here to have components that are reusable with every frontend technology. It doesn't matter if you are using angular or React, you can always import the Components from the pattern library.

At the moment, we only use Proposed Standard Custom Element, therefore it will run natively on Safari and Chrome on mobile and desktop.

Are you not familiar with Webcomponents? Then stop here and read this (chapter Introduction and Specification): https://www.webcomponents.org/introduction

To know how they work in your browser go to the w3c Spec. Here the link to the custom element for example: https://www.w3.org/TR/custom-elements/

Hold on, don't re-invent the wheel! Check if that what you have to do already exists: https://www.webcomponents.org/

Setting things up with your Repo:

Well first of all install the npm module:

npm install --save @axa-ch/patterns-library or while still in development better npm install https://github.com/axa-ch/patterns-library.git --save

Then, you can add the component of your choice simply by importing the index.js which is contained in the /dist/components/** folder! Styles, HTML and JS will be all in one file!

As an example:

Import the button via import '@axa-ch/patterns-library/dist/components/m-button' in your index.js to be able to use the button. Wherever you want, add <axa-button>Hello</axa-button> in your html and like magic, the button will work!

If a component has dependecies to other components, you will have to add them as well. The button in the example above actually has a dependency to a-icon. So we will have to include it as well. Remember, a molecule or an organism will always have dependecies to other components. These components will work also by adding them directly with the <script src='@axa-ch/patterns-library/dist/components/m-button'></script> tag.

To use the webcomponents with older browsers, import the polyfills which are available under <script src="node_modules/@axa-ch/patterns-library/dist/app/webcomponents-lite.js"></script>

A quick overview what they do: webcomponents-lite.js includes all the polyfills needed for ES6 ready browsers and includes polyfills for all 4 parts of the webcomponents specs. es6-polyfills.js are all the polyfills needed for ie11. Alternativly to webcomponents-lite.js, webcomponents-loader.js loads the polyfills that is needed asynchronously via AJAX.

If you are using your own framework, be aware to convert the webcponents to a component for your framework (simple components like m-button does not need to be converted):

Do you love angular >= 2? Here a helpfull link for you: https://www.sitepen.com/blog/2017/09/14/using-web-components-with-angular/

Do you love React? Here a helpfull link for you: https://github.com/webcomponents/react-integration

Do you love Vue? Here a helpfull link for you: https://alligator.io/vuejs/vue-integrate-web-components/

Adding your first Pattern Library component:

Super easy: Read the specs and then just execute npm run new. Follow the instruction on the CLI.

Main NPM commands:

  • To build to dist folder, simply run npm run build
  • to run server and watchers (this is what you want while you are developing) npm run serve
  • to run the PROD server npm run serve-build-prod

How do we release a new version

Please run npm run release and follow the steps in the wizard

For more information: We have a strict strategy for releasing new versions of the Patterns Library. Please refer to the wiki: https://github.com/axa-ch/patterns-library/wiki/Crafting-a-release

Usage guide - With just Webcomponents (no framework)

this code snipped is tested on FF, IE11, EDGE, Chrome, Safari, Mobile Chrome, Mobile Safari

Here an example on how to use the component button and typo in your project. The component Typo is used to show you all the possible fonts avaiable. The index.css contains all the basic page settings

<html>
  <head>
    <link rel="stylesheet" href="http://localhost:8080/node_modules/patterns-library/dist/index.css">
  </head>
  <body>

    <script src="http://localhost:8080/node_modules/patterns-library/dist/app/es6-polyfills.js"></script>
    <script src="http://localhost:8080/node_modules/patterns-library/dist/app/webcomponents-lite.js"></script>
    <script src="http://localhost:8080/node_modules/patterns-library/dist/components/core/index.js"></script>
    <script src="http://localhost:8080/node_modules/patterns-library/dist/components/m-button/index.js"></script>
    <script src="http://localhost:8080/node_modules/patterns-library/dist/components/a-typo/index.js"></script>

    <axa-core icons-path="./assets/icons/icons.svg"></axa-core>

    <axa-button>I'm a button</axa-button>
    <axa-typo></axa-typo>
  </body>
</html>

Developers Guide:

Publish / Subscribe between webcomponents

To listen to events and triggers between components, we use some decoupled events. This logic is included in the BaseComponent class and is available for every component.

The publish/subscribe system use native Custom Events (https://dom.spec.whatwg.org/#interface-customevent). Per default they don't bubble and don't cancel (no prevent default). The event name is name spaced with a slash.

Here is the declaration of the publish function:

/**
 * Publish a message regarding a given topic.
 *
 * @param {String} topic - A string defining the topic to publish to.
 * @param {*} arg - The data associate with the generated event.
 * @param {Element} [node=document] - The node to publish message to.
 */
export function publish(topic, arg, node = document) {
  ...
}

The event, per default, is propagated through the document node:

Alt text

Example:

// COMP A triggers
publish('device-state/change', state);

// COMP B listens
subscribe('device-state/change', (state) => {
  ...
});

// As all the events are asynchronously, if COMP A want to know if someone specifically subscribe
// to the publish we have a system event for it. Lets say N components will or have subscribed to COMP A, but COMP A
// wants to know only when COMP B subscribed, he can listen to the Subscription event of COMP B:
subscribe('pubsub/onsubscribe/device-state/change', () => {});

Alternatively, you can set a custom node where the event will be triggered on:

Alt text

The concept is similar to the description above, with the difference that you can pass a custom node.

// context node here is used to encapsulate event listeners and triggers to a single container.
// In the concrete example, we want that not every mobile navigation listen to a publish event, but
// only that one which is inside a certain context. Here could be that axa-header is the containing
// context and axa navigation mobile have to listen to axa main navigation. In order to be sure that
// it listens only to one axa-header and not all potential other ones, we use the context
publish('main-navigation-mobile/close', null, this._contextNode);
subscribe('main-navigation-mobile/close', (arg) => {}, this._contextNode);

Context enabler and context listener

TODO.

Guide to for the base components:

TODO.

1.0.0-beta.0

4 years ago

1.0.0-beta.1

4 years ago

2.0.0

5 years ago

2.0.1-beta.264

5 years ago

2.0.1-beta.263

5 years ago

2.0.1-beta.262

5 years ago

2.0.1-beta.261

5 years ago

2.0.1-beta.260

5 years ago

2.0.1-beta.259

5 years ago

2.0.1-beta.258

5 years ago

2.0.1-beta.257

5 years ago

2.0.1-beta.256

5 years ago

2.0.1-beta.255

5 years ago

2.0.1-beta.254

5 years ago

2.0.1-beta.253

5 years ago

2.0.1-beta.252

5 years ago

2.0.1-beta.251

5 years ago

2.0.1-beta.250

5 years ago

2.0.1-beta.249

5 years ago

2.0.1-beta.248

5 years ago

2.0.1-beta.247

5 years ago

2.0.1-beta.246

5 years ago

2.0.1-beta.245

5 years ago

2.0.1-beta.244

5 years ago

2.0.1-beta.243

5 years ago

2.0.1-beta.242

5 years ago

2.0.1-beta.241

5 years ago

2.0.1-beta.240

5 years ago

2.0.1-beta.239

5 years ago

2.0.1-beta.238

5 years ago

2.0.1-beta.237

5 years ago

2.0.1-beta.236

5 years ago

2.0.1-beta.235

5 years ago

2.0.1-beta.234

5 years ago

2.0.1-beta.233

5 years ago

2.0.1-beta.232

5 years ago

2.0.1-beta.231

5 years ago

2.0.1-beta.230

5 years ago

2.0.1-beta.229

5 years ago

2.0.1-beta.228

5 years ago

2.0.1-beta.227

5 years ago

2.0.1-beta.226

5 years ago

2.0.1-beta.225

5 years ago

2.0.1-beta.224

5 years ago

2.0.1-beta.223

5 years ago

2.0.1-beta.222

5 years ago

2.0.1-beta.221

5 years ago

2.0.1-beta.220

5 years ago

2.0.1-beta.219

5 years ago

2.0.1-beta.218

5 years ago

2.0.1-beta.217

5 years ago

2.0.1-beta.216

5 years ago

2.0.1-beta.215

5 years ago

2.0.1-beta.214

5 years ago

2.0.1-beta.213

5 years ago

2.0.1-beta.212

5 years ago

2.0.1-beta.211

5 years ago

2.0.1-beta.210

5 years ago

2.0.1-beta.209

5 years ago

2.0.1-beta.208

6 years ago

2.0.1-beta.207

6 years ago

2.0.1-beta.206

6 years ago

2.0.1-beta.205

6 years ago

2.0.1-beta.204

6 years ago

2.0.1-beta.203

6 years ago

2.0.1-beta.202

6 years ago

2.0.1-beta.201

6 years ago

2.0.1-beta.200

6 years ago

2.0.1-beta.199

6 years ago

2.0.1-beta.198

6 years ago

2.0.1-beta.197

6 years ago

2.0.1-beta.196

6 years ago

2.0.1-beta.195

6 years ago

2.0.1-beta.194

6 years ago

2.0.1-beta.193

6 years ago

2.0.1-beta.192

6 years ago

2.0.1-beta.191

6 years ago

2.0.1-beta.190

6 years ago

2.0.1-beta.189

6 years ago

2.0.1-beta.188

6 years ago

2.0.1-beta.187

6 years ago

2.0.1-beta.186

6 years ago

2.0.1-beta.185

6 years ago

2.0.1-beta.184

6 years ago

2.0.1-beta.183

6 years ago

2.0.1-beta.182

6 years ago

2.0.1-beta.181

6 years ago

2.0.1-beta.180

6 years ago

2.0.1-beta.179

6 years ago

2.0.1-beta.178

6 years ago

2.0.1-beta.177

6 years ago

2.0.1-beta.176

6 years ago

2.0.1-beta.175

6 years ago

2.0.1-beta.174

6 years ago

2.0.1-beta.173

6 years ago

2.0.1-beta.172

6 years ago

2.0.1-beta.171

6 years ago

2.0.1-beta.170

6 years ago

2.0.1-beta.169

6 years ago

2.0.1-beta.168

6 years ago

2.0.1-beta.167

6 years ago

2.0.1-beta.166

6 years ago

2.0.1-beta.165

6 years ago

2.0.1-beta.164

6 years ago

2.0.1-beta.163

6 years ago

2.0.1-beta.162

6 years ago

2.0.1-beta.161

6 years ago

2.0.1-beta.160

6 years ago

2.0.1-beta.159

6 years ago

2.0.1-beta.158

6 years ago

2.0.1-beta.157

6 years ago

2.0.1-beta.156

6 years ago

2.0.1-beta.155

6 years ago

2.0.1-beta.154

6 years ago

2.0.1-beta.153

6 years ago

2.0.1-beta.152

6 years ago

2.0.1-beta.151

6 years ago

2.0.1-beta.150

6 years ago

2.0.1-beta.149

6 years ago

2.0.1-beta.148

6 years ago

2.0.1-beta.147

6 years ago

2.0.1-beta.146

6 years ago

2.0.1-beta.145

6 years ago

2.0.1-beta.144

6 years ago

2.0.1-beta.143

6 years ago

2.0.1-beta.142

6 years ago

2.0.1-beta.141

6 years ago

2.0.1-beta.140

6 years ago

2.0.1-beta.139

6 years ago

2.0.1-beta.138

6 years ago

2.0.1-beta.137

6 years ago

2.0.1-beta.136

6 years ago

2.0.1-beta.135

6 years ago

2.0.1-beta.134

6 years ago

2.0.1-beta.133

6 years ago

2.0.1-beta.132

6 years ago

2.0.1-beta.131

6 years ago

2.0.1-beta.130

6 years ago

2.0.1-beta.129

6 years ago

2.0.1-beta.128

6 years ago

2.0.1-beta.127

6 years ago

2.0.1-beta.126

6 years ago

2.0.1-beta.125

6 years ago

2.0.1-beta.124

6 years ago

2.0.1-beta.123

6 years ago

2.0.1-beta.122

6 years ago

2.0.1-beta.121

6 years ago

2.0.1-beta.120

6 years ago

2.0.1-beta.119

6 years ago

2.0.1-beta.118

6 years ago

2.0.1-beta.117

6 years ago

2.0.1-beta.116

6 years ago

2.0.1-beta.115

6 years ago

2.0.1-beta.114

6 years ago

2.0.1-beta.113

6 years ago

2.0.1-beta.112

6 years ago

2.0.1-beta.111

6 years ago

2.0.1-beta.110

6 years ago

2.0.1-beta.109

6 years ago

2.0.1-beta.108

6 years ago

2.0.1-beta.107

6 years ago

2.0.1-beta.106

6 years ago

2.0.1-beta.105

6 years ago

2.0.1-beta.104

6 years ago

2.0.1-beta.103

6 years ago

2.0.1-beta.102

6 years ago

2.0.1-beta.101

6 years ago

2.0.1-beta.100

6 years ago

2.0.1-beta.99

6 years ago

2.0.1-beta.98

6 years ago

2.0.1-beta.97

6 years ago

2.0.1-beta.96

6 years ago

2.0.1-beta.95

6 years ago

2.0.1-beta.94

6 years ago

2.0.1-beta.93

6 years ago

2.0.1-beta.92

6 years ago

2.0.1-beta.91

6 years ago

2.0.1-beta.90

6 years ago

2.0.1-beta.89

6 years ago

2.0.1-beta.88

6 years ago

2.0.1-beta.87

6 years ago

2.0.1-beta.86

6 years ago

2.0.1-beta.85

6 years ago

2.0.1-beta.84

6 years ago

2.0.1-beta.83

6 years ago

2.0.1-beta.82

6 years ago

2.0.1-beta.81

6 years ago

2.0.1-beta.80

6 years ago

2.0.1-beta.79

6 years ago

2.0.1-beta.78

6 years ago

2.0.1-beta.77

6 years ago

2.0.1-beta.76

6 years ago

2.0.1-beta.75

6 years ago

2.0.1-beta.74

6 years ago

2.0.1-beta.73

6 years ago

2.0.1-beta.72

6 years ago

2.0.1-beta.71

6 years ago

2.0.1-beta.70

6 years ago

2.0.1-beta.69

6 years ago

2.0.1-beta.68

6 years ago

2.0.1-beta.67

6 years ago

2.0.1-beta.66

6 years ago

2.0.1-beta.65

6 years ago

2.0.1-beta.64

6 years ago

2.0.1-beta.63

6 years ago

2.0.1-beta.62

6 years ago

2.0.1-beta.61

6 years ago

2.0.1-beta.60

6 years ago

2.0.1-beta.59

6 years ago

2.0.1-beta.58

6 years ago

2.0.1-beta.57

6 years ago

2.0.1-beta.56

6 years ago

2.0.1-beta.55

6 years ago

2.0.1-beta.54

6 years ago

2.0.1-beta.53

6 years ago

2.0.1-beta.52

6 years ago

2.0.1-beta.51

6 years ago

2.0.1-beta.50

6 years ago

2.0.1-beta.49

6 years ago

2.0.1-beta.48

6 years ago

2.0.1-beta.47

6 years ago

2.0.1-beta.46

6 years ago

2.0.1-beta.45

6 years ago

2.0.1-beta.44

6 years ago

2.0.1-beta.43

6 years ago

2.0.1-beta.42

6 years ago

2.0.1-beta.41

6 years ago

2.0.1-beta.40

6 years ago

2.0.1-beta.39

6 years ago

2.0.1-beta.38

6 years ago

2.0.1-beta.37

6 years ago

2.0.1-beta.36

6 years ago

2.0.1-beta.35

6 years ago

2.0.1-beta.34

6 years ago

2.0.1-beta.33

6 years ago

2.0.1-beta.32

6 years ago

2.0.1-beta.31

6 years ago

2.0.1-beta.30

6 years ago

2.0.1-beta.29

6 years ago

2.0.1-beta.28

6 years ago

2.0.1-beta.27

6 years ago

2.0.1-beta.26

6 years ago

2.0.1-beta.25

6 years ago

2.0.1-beta.24

6 years ago

2.0.1-beta.23

6 years ago

2.0.1-beta.22

6 years ago

2.0.1-beta.21

6 years ago

2.0.1-beta.20

6 years ago

2.0.1-beta.19

6 years ago

2.0.1-beta.18

6 years ago

2.0.1-beta.17

6 years ago

2.0.1-beta.16

6 years ago

2.0.1-beta.15

6 years ago

2.0.1-beta.14

6 years ago

2.0.1-beta.13

6 years ago

2.0.1-beta.9

6 years ago

2.0.1-beta.8

6 years ago

2.0.1-beta.7

6 years ago

2.0.1-beta.6

6 years ago

2.0.1-beta.5

6 years ago

2.0.1-beta.4

6 years ago

2.0.1-beta.3

6 years ago

2.0.1-beta.2

6 years ago

2.0.1-beta.1

6 years ago

2.0.1-beta.0

6 years ago

2.0.1-beta

6 years ago

2.0.0-beta

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago