0.0.239 • Published 5 years ago

@rstor/rstor-ui-library v0.0.239

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Atrio UI Library

This project was generated with Angular CLI version 1.2.0. This is an application containing the Atrio UI library which can be exported using the ng-packagr. New components (and modules) can be added by using the Angular CLI and following a few simple steps. The selector prefix for the components in this library is "rui-".

HOW TO CREATE A NEW LIBRARY PACKAGE VERSION

A new package needs to be created each time you have added or modified a component.

  1. Install Run nvm use to set the expected Node version. Run npm install to install all the dependencies if you haven't already.

  2. (OPTIONAL) Create and test the package locally Run npm run create-dev-package from the root project folder to compile and package the TypeScript library to Angular Package Format. This will create a dist folder with a tarball called atrio-ui-library-x.x.x.tgz with the x.x.x part being the version number from the package.json file. You can use this file to test the library locally from your UI application by temporary adding "@atrio/atrio-ui-library": "file:<local_path>/atrio-ui-library/dist/atrio-ui-library-x.x.x.tgz" to the package.json.

  3. Update private npm package Create a PR for master. Once it is approved (by review, CI tests and linting) and merged a new npm package will automatically be uploaded to our private npm. Please note! Do not update the package version number manually, the CI will do that on merge with master.

  4. Update the atrio-ui-library reference in your UI application Depending on how you specified your version (^, ~, > etc) and if your update was major, minor or patch you might need to update the "@atrio/atrio-ui-library" dependency in your UI application's package.json to get this latest version.

HOW TO USE THE LIBRARY IN ANOTHER APP

This requires that the package has been created according to the steps above. The target app can have Angular Material installed, but it is not mandatory, since the components in the UI library come with their own material dependiencies. The UI library's Material theme however needs to be imported, see point 4.

  1. Install the dependency Go to your target application run npm install --save @atrio/atrio-ui-library. This will install the latest atrio-ui-library from our private npm. Make sure the file .npmrc is present in the root of your application and contains a readonly access token to our private npm.

  2. Link the assets Some assets of the library (fonts and svg icons) need to be available for the entire application, not just to the components of of the library itself. Add the following to the apps.assets array in the .angular-cli.json:

    { 
    	"glob": "**/*", 
    	"input": "../node_modules/@atrio/atrio-ui-library/src/assets", 
    	"output": "./assets/rui-assets/" 
    }

    Notice: If your app is based in Angular 6 you have to add the previous lines into angular.json file instead.

    This will make sure the UI library assets are made available as assets under the subfolder rui-assets so that they don't conflict with any other assets.

  3. Configure Angular Material styles

3.1. Make sure you application is configured to use Sass (.scss) so that it works with the custom Material theming.

3.2. From you applications main style file (e.g. styles.scss) add the following line at the top
`@import '../node_modules/@atrio/atrio-ui-library/src/material-themes.scss';`. If you need to change anything in the main theme, you need to do that before importing the material-themes.scss. Here is a simple example of how it could look:    

```
@import '~@atrio/atrio-ui-library/src/_variables.scss';
$rui-color-main-nav-logo-background: $rui-color-green;
@import '~@atrio/atrio-ui-library/src/_material-themes.scss';
```    

3.3. Add the class `material-light-theme` to the HTML body in `index.html`, or use a wrapper element in a component if you want to be able to use multiple themes.

3.4. Add the class `mat-typography` to the HTML body in `index.html`.
  1. Configure the icons The UI library icons are added to the Angular Material's MatIconRegistry under the namespace rui so that they don't conflict with any default Angular or application specific icons.

    4.1. Import the UI library's IconsModule to your app.module.ts using import { IconsModule } from '@atrio/atrio-ui-library';Don't forget to add the module to the imports array.

    4.2 Inject the IconsService in your apps root component (app.component.ts) by using import { IconsService } from '@atrio/atrio-ui-library'; and set the constructor like constructor(IconsService: IconsService){}

    4.3 Make sure your app imports the HttpClientModule in the root module of your application (often called app.module.ts).

    	_Please Note!_ : 

    This makes the icons available to all components of your application, including the components of the UI library which might need them. But in order to actually use the icons in your own component be sure the module of your component imports the MatIconModule. e.g. import { MatIconModule } from '@angular/material';.

  2. Import and use as normal Import the modules (components) that you want to use as you would with any Angular package. E.g. import { FancyButtonModule } from '@atrio/atrio-ui-library';

  3. Modified TypeScript configuration (only for Angular 6)

    Add the following into compilerOptions of the tsconfig.json file:

    "paths": {
      "@angular/*": ["node_modules/@angular/*"] 
    }
  4. RxJS Compatibility (only for Angular 6)

Since this library was implemented under Angular 5 it's necessary to install rxjs-compat package to get backwards compatibility with RxJS previous versions.

npm install --save rxjs-compat

HOW TO USE THE LIBRARY IN ANOTHER APP - LINK MODE

This section will explain the steps to use the library without installation. To link it, follow this steps:

  • Create package and link it using this command npm run create-package-and-link. (You have to run this command every time you want to have changes linked to you main app)
  • In your Angular App with atrio ui lib dependence*:
    • Go to your app node_modules folder and run npm link @atrio/atrio-ui-library
    • Run the app adding the flag --preserve-symlinks.
    • To restore library, go to node_modules folder an run npm unlink @atrio/atrio-ui-library and run npm install @atrio/atrio-ui-library.

*If you are using this library in Marinara project, you have some scripts to do the link and unlink process, please read marinara readme file.

HOW TO ADD COMPONENTS

This section assumes that the reader is somewhat familiar with Angular 4.X and the Angular CLI. Lets examplify with a new component called fancy-button.

  1. Install If not already done, run npm install in the atrio-ui-library folder.

  2. Start the development server Run ng serve. Navigate to http://localhost:4300/.

  3. Create a component with its own module. We use one module per component. Each component/module should have its own folder which should be a subfolder of the app/modules folder. E.g. generate the module in a folder with the same name using ng generate module modules/fancy-button then generate the component in the same folder using ng generate component modules/fancy-button. If you need to use colors, use the avilable CSS properties for dynamic colors that should follow current theme (e.g. var(--rui-color-primary) and SASS variables for colors that never change (e.g. $rui-color-blue).

  4. Create the wiring 4.1 Export the FancyButtonComponent in the fancy-button.module.ts. 4.2 Import the appropriate demo module, e.g. demo-components.module.ts. 4.3 Then add your component to the demo component, e.g. demo-components.component.html so that you can try it out and so that others can see it working. Add a small descrition on how to use it. In the future we probabley want to make this demo a bit more sophisticated.

  5. Export your module from the public_api.ts E.g. add the line export * from './src/app/modules/fancy-button/fancy-button.module'; to the file.

  6. Add any external dependencies If you are using new any external libraries they should be added to the file ng-package.json under lib:externals.

  7. Create the library package See instructions above. (The lastest-package distribution folder of the UI library is part of the git repo for easy setup.)

HOW CREATE A CUSTOM THEME (BRANDING)

Please note that this information is for POC and client specific theming. All Atrio apps will by default use the same blue based theme, only the color of the logo background in the main navigion will be different.

The atrio-ui-library can be easily themed for clients and demos by simply changing some of the SCSS variables that the look and feel is based on. For simple theme changes you can add any of the "theme variables" below in your consuming application's global styles.scss before it imports the _material-themes.scss. You can also adjust the theme by changing these variables in the library itself.

The theme variables are defined in src/app/scss/_variables.scss. Common steps for theming include:

  1. If needed replace the logo src/assets/rui-assets/images/logo.png with the logo of the client.
  2. Set $rui-custom-theme-display to initial. This will enable the "Powered by Atrio" image in the footer.
  3. Set $rui-show-company-name to none if you don't want to show the company name in the footer.
  4. Adjust the height of the $rui-toolbar-height if needed.
  5. Adjust the following variables to match your color needs
    • $rui-color-primary -> Changes things like buttons, header, progress bar and the primary-attribute color etc.
    • $rui-color-accent -> Changes checkboxes, radiobuttons, sliders and possily other components that use the accent color somehow.
    • $rui-color-background -> Changes the background color of the app.
    • $rui-color-panel-background -> Changes the background color of panels and the footer.
    • $rui-color-foreground -> Changes the default color of headers, paragraphs, input texts, input labels etc.
    • $rui-color-main-nav-background -> Background for the header and the sub-header components.
    • $rui-color-links -> Color for links ( tags).
    • $rui-color-links-focus -> Color for focused links.
    • $rui-color-icon-primary -> multi colored icon color.
    • $rui-color-icon-secondary -> multi colored icon color.
    • $rui-color-icon-base -> multi colored icon color.

HOW TO ADD ICONS

The atrio-ui-library contains two types of icons, multi and singel colored. Multi colored icons are the more complex ones with 3 colors, representing specific atrio concepts or file types. Single colored icons are simple icons, like close and back icons that come in only one color. The icons should be in the SVG format.

  1. Make sure the file is correctly named. The name of the file should also be the name of the icon, e.g. the bucket icon file is named bucket.svg. Separate multiple words with dash.
  2. Add the svg file to assets/rui-assets/svg-icons
  3. Add the icon name to the icons or the fileTypesIcons arrays in the icons.service.ts.
  4. Open the svg file and make sure the title tag is the name of the icon.
  5. Make sure there are no ID attributes in the SVG elements, delete if there are any.
  6. For single colored icons, make sure the fill attribute is set to currentColor. For multi colored you probably need to override (but not replace) both the fill and stroke attributes with corresponding CSS classes. Our default icons currently use the colors #4390BC, #DCEFFE and FFFFFF (aka FFF or simply white) and they correspond to our variables $rui-color-icon-primary, $rui-color-icon-secondary and $rui-color-icon-base. Since there are 3 colors and 2 possible ways of using them in the SVG file we have 6 icon color classes to choose from:
    • .rui-color-icon-primary-fill (#4390BC)
    • .rui-color-icon-primary-stroke (#4390BC)
    • .rui-color-icon-secondary-fill (#DCEFFE)
    • .rui-color-icon-secondary-stroke (#DCEFFE)
    • .rui-color-icon-base-fill (#FFFFFF)
    • .rui-color-icon-base-stroke (#FFFFFF)

As an example the following fictive paths

<path d="..." fill="#4390BC" fill-rule="nonzero"></path>
<path d="..." stroke="#DCEFFE" fill-rule="nonzero"></path>
<path d="..." stroke="#FFFFFF" fill="white" fill-rule="nonzero"></path>

Should be changed into

<path d="..." fill="#4390BC" class="rui-color-icon-primary-fill" fill-rule="nonzero"></path>
<path d="..." stroke="#DCEFFE" class="rui-color-icon-secondary-stroke" fill-rule="nonzero"></path>
<path d="..." stroke="#FFFFFF" class="rui-color-icon-base-fill rui-color-icon-base-stroke" fill-rule="nonzero"></path>

We keep the original fill and stroke so that the image still can be correctly viewed again in an SVG editor.

More info on theming, colors and variables

For "constants" like our standard blue color (e.g. '$rui-color-blue') you should use the SASS variables and for colors that might change depending on theming you should use the CSS properties (e.g. 'var(--rui-color-primary)')

If your app uses the atrio-ui-library it will get its colors in two ways. First, Material components like buttons, get their colors from the theme definition in _material-themes.scss. That theme definition in turn uses the atrio specific _variables.scss. Second, library specific elements use the static colors in _variables.scss and the dynamic CSS properties in _default-theme.scss.

Since all SASS code in the atrio-ui-library is compiled when we create the package all SASS variables are lost for the atrio components that get their inline HTML/STYLE replaced with the actual HEX colors or CSS properties (variables). Hence, in order to control the color and other theme attributes of our in-house components from outside the library we need to use CSS properties in our components. These CSS properties are declared in the root context in _default-theme.scss and if they are overwritten by the consuming application, the components will reflect that change. But since the Angular Material SASS theme creation functions require SASS variables we need to work with both CSS properties and SASS variables.

Therefor the consuming application will get a copy of these SASS files (added to the package via an npm script) so that it can reuse the SASS variables and easily create a Material theme itself. The theme class is added to the body of the consuming application which decides how the material components will look. By simply declaring new values for the SASS variables in your consuming app you can in one go change both the Material theme and the CSS properties that controls the atrio-ui-library inhouse components. This is how it works in your consuming apps main styles.css.

// Import the variables to get access to statics colors etc.
// All themable variables are declared as "default" so they will only get its 
// value from this file unless they aren't delared anywhere else, before OR after this import.
@import '~@atrio/atrio-ui-library/src/_variables.scss';

// Here you can declare or override any library specific SASS variables.
$rui-color-main-nav-logo-background: $rui-color-green;

// By importing this file two important things happen. First, it will in turn import a default theme.css 
// that will set CSS properties based on the corresponding current values of the SASS variables. 
// That means that the CSS properties and SASS variables are now in sync even if SASS variables were overwritten. 
// Second, it will generate the Angular Material theme based on the current SASS variables.
@import '~@atrio/atrio-ui-library/src/_material-themes.scss';

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|module.

Running unit tests

Run ng test to execute the unit tests via Karma.

0.0.239

5 years ago

0.0.238

5 years ago

0.0.237

5 years ago

0.0.236

5 years ago

0.0.235

5 years ago

0.0.234

5 years ago

0.0.233

5 years ago

0.0.232

5 years ago

0.0.231

5 years ago

0.0.230

5 years ago

0.0.229

5 years ago

0.0.228

5 years ago

0.0.227

5 years ago

0.0.226

5 years ago

0.0.225

5 years ago

0.0.224

5 years ago

0.0.223

5 years ago

0.0.222

5 years ago

0.0.221

6 years ago

0.0.220

6 years ago

0.0.219

6 years ago

0.0.218

6 years ago

0.0.217

6 years ago

0.0.216

6 years ago

0.0.215

6 years ago

0.0.214

6 years ago

0.0.213

6 years ago

0.0.212

6 years ago

0.0.211

6 years ago

0.0.210

6 years ago

0.0.209

6 years ago

0.0.208

6 years ago

0.0.207

6 years ago

0.0.206

6 years ago

0.0.205

6 years ago

0.0.204

6 years ago

0.0.203

6 years ago

0.0.202

6 years ago

0.0.201

6 years ago

0.0.200

6 years ago

0.0.199

6 years ago

0.0.198

6 years ago

0.0.197

6 years ago

0.0.196

6 years ago

0.0.195

6 years ago

0.0.194

6 years ago

0.0.193

6 years ago

0.0.192

6 years ago

0.0.191

6 years ago

0.0.190

6 years ago

0.0.189

6 years ago

0.0.188

6 years ago

0.0.187

6 years ago

0.0.186

6 years ago

0.0.185

6 years ago

0.0.184

6 years ago

0.0.183

6 years ago

0.0.182

6 years ago

0.0.181

6 years ago

0.0.180

6 years ago

0.0.179

6 years ago

0.0.178

6 years ago

0.0.177

6 years ago

0.0.176

6 years ago

0.0.175

6 years ago

0.0.174

6 years ago

0.0.173

6 years ago

0.0.172

6 years ago

0.0.171

6 years ago

0.0.170

6 years ago

0.0.169

6 years ago

0.0.168

6 years ago

0.0.167

6 years ago

0.0.166

6 years ago

0.0.165

6 years ago

0.0.164

6 years ago

0.0.163

6 years ago

0.0.162

6 years ago

0.0.161

6 years ago

0.0.160

6 years ago

0.0.159

6 years ago

0.0.158

6 years ago

0.0.157

6 years ago

0.0.156

6 years ago

0.0.155

6 years ago

0.0.154

6 years ago

0.0.153

6 years ago

0.0.152

6 years ago

0.0.151

6 years ago

0.0.150

6 years ago

0.0.149

6 years ago

0.0.148

6 years ago

0.0.147

6 years ago

0.0.146

6 years ago

0.0.145

6 years ago

0.0.144

6 years ago

0.0.143

6 years ago

0.0.142

6 years ago

0.0.141

6 years ago

0.0.140

6 years ago

0.0.139

6 years ago

0.0.138

6 years ago

0.0.137

6 years ago

0.0.136

6 years ago

0.0.135

6 years ago

0.0.134

6 years ago

0.0.133

6 years ago

0.0.132

6 years ago

0.0.131

6 years ago

0.0.130

6 years ago

0.0.129

6 years ago

0.0.128

6 years ago

0.0.127

6 years ago

0.0.126

6 years ago

0.0.125

6 years ago

0.0.124

6 years ago

0.0.123

6 years ago

0.0.122

6 years ago

0.0.121

6 years ago

0.0.120

6 years ago

0.0.119

6 years ago

0.0.118

6 years ago

0.0.117

6 years ago

0.0.116

6 years ago

0.0.115

6 years ago

0.0.114

6 years ago

0.0.113

6 years ago

0.0.112

6 years ago

0.0.111

6 years ago

0.0.110

6 years ago

0.0.109

6 years ago

0.0.108

6 years ago

0.0.107

6 years ago

0.0.106

6 years ago

0.0.105

6 years ago

0.0.104

6 years ago

0.0.103

6 years ago

0.0.102

6 years ago

0.0.101

6 years ago

0.0.100

6 years ago

0.0.99

6 years ago

0.0.98

6 years ago

0.0.97

6 years ago

0.0.96

6 years ago

0.0.95

6 years ago

0.0.94

6 years ago

0.0.93

6 years ago

0.0.92

6 years ago

0.0.91

6 years ago

0.0.90

6 years ago

0.0.89

6 years ago

0.0.88

6 years ago

0.0.87

6 years ago

0.0.86

6 years ago

0.0.85

6 years ago

0.0.84

6 years ago

0.0.83

6 years ago

0.0.82

6 years ago

0.0.81

6 years ago

0.0.80

6 years ago

0.0.79

6 years ago

0.0.78

6 years ago

0.0.77

6 years ago

0.0.76

6 years ago

0.0.75

6 years ago

0.0.74

6 years ago

0.0.73

6 years ago

0.0.72

6 years ago

0.0.71

6 years ago

0.0.70

6 years ago

0.0.69

6 years ago

0.0.68

6 years ago

0.0.67

6 years ago

0.0.65

6 years ago

0.0.64

6 years ago

0.0.63

6 years ago

0.0.62

6 years ago

0.0.61

6 years ago

0.0.60

6 years ago

0.0.59

6 years ago

0.0.58

6 years ago

0.0.57

6 years ago

0.0.56

6 years ago

0.0.55

6 years ago

0.0.54

6 years ago

0.0.53

6 years ago

0.0.52

6 years ago

0.0.51

6 years ago

0.0.50

6 years ago

0.0.49

6 years ago

0.0.48

6 years ago

0.0.47

6 years ago

0.0.46

6 years ago

0.0.45

6 years ago

0.0.44

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago