Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Create, Extend, and Publish Your Library with A...

Create, Extend, and Publish Your Library with Angular

Create, Extend, and Publish Your Library with Angular

Dany Paredes

November 30, 2024
Tweet

More Decks by Dany Paredes

Other Decks in Programming

Transcript

  1. Agenda 1. Why create a library? 2. Scenario 3. Creating

    our first library 4. Creating our Component 5. Publishing locally 6. Using our library locally 7. Themes
  2. About Me Dany Paredes 🏀 NBA 🏆🅰 GDE x 4

    🥇 Telerik Champion 󰜻Kendo UI / Google Dev Library http://danywalls.com | @danywalls
  3. Scenario We work for a large accounting software company that

    needs to release two new applications for banking and registration. Both applications require a set of buttons. What can we do? - Create identical buttons for both the banking and registration applications. - Share the CSS between both applications and duplicate the button component. - Make sure we think long term: What would happen if the company changed its brand color? This should be something we ought to be able to update in the future without too much hassle.
  4. ng generate library my-company --prefix=donweb The –prefix= changes your component

    prefix from <app-my-lib> to <donweb-my-component>, by default. Generate Library
  5. CSS Custom Properties Theming CSS Custom Properties (also known as

    CSS Variables) helps to use variable to and reuse values throughout your stylesheets
  6. :root { --primary-color: #3498db; --text-color: #333; } CSS custom properties

    (variables) https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties
  7. :root { --btn-bg-color: rgb(55, 114, 222); --btn-color: rgb(134, 206, 33);

    } donweb-button[data-theme="summer"] { --btn-bg-color: rgb(222, 24, 114); --btn-color: rgb(143, 218, 43); } donweb-button[data-theme="spring"] { --btn-bg-color: rgb(199, 206, 57); --btn-color: rgb(179, 29, 225); } Theme.css
  8. What next? - What happened if I donʼt like the

    sprint or summer colors? - How to publish to npm ? - If happen I want to extends my library with other ?
  9. NPM

  10. Tips Nx: Great nx.dev Great tool for monorepo all code

    in one place with consistency and easy dependency management. StoryBook: Simplify sandbox for other developers and the company to play with the UI components with documentation and user cases Stories) easy. storybook.js.org Cypress: cypress.io cover e2e and cypress component testing and test your components quickly. Jest: Angular testing library + jestjs.io Unit test for services and business.
  11. Resources - https://github.com/danywalls/donweb_landing - https://github.com/danywalls/donweb-ui/tree/master/projects/do nweb-ui - Angular - Workspace

    and project file structure - https://angular.io/guide/creating-libraries - https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_c ustom_properties