Code Monkey home page Code Monkey logo

jsapi-styles's Introduction

This repository has been deprecated and merged into @esri/arcgis-js-cli

JSAPI Styles

This utility makes it easier to creating your own Sass theme for ArcGIS API for JavaScript applications.

By working with Sass, you no longer need to figure out CSS overrides by brute-force, which is brittle and not scalable.

Requirements

  • node/npm
  • Working knowledge of Sass is highly recommended

Setup

  • npm install
  • npm run setup- sets up the development environment, which will lay out the Sass theme files. Be careful, this command will override any changes to my-theme/main.scss.
  • npm start - launches a preview page that will automatically reload when making changes.

Structure

The following is a simplified look at the styles folder structure:

sass/
  +-- base/
  |   +-- colors/
  |   +-- fonts/
  |   +-- icons/
  |   +-- images/
  |   +-- widgets/
  |
  +-- examples/
  |
  +-- my-theme/
      |
      +-- main.scss
  • base/ contains the foundation for all themes. Here is where we define variables, functions, mixins, and other helpers, such as color, font, and icon resources.

  • examples/ contains examples for different themes provided in the ArcGIS API for JavaScript.

  • my-theme/ contains your custom theme's main file.

Customizing

Under my-theme/ you will find main.scss. This file already imports the core for your theme, so the simplest way to start customizing is to to define variable overrides.

/*
  Theme: My Theme
*/

// variable overrides
$some_variable_to_override : <overridden value>;

// import theme base
@import "../base/core";

If you want more control, you can also create the theme to your liking and import any dependencies from base as needed.

@import "../base/mixins";  // mixins are now available for use

// custom scss goes here

By default _core.scss will include all widget styles. You can make the distributable theme leaner by excluding widget styles. Each widget has a corresponding variable that controls whether they are included in the theme or not. Set these to false for anything you want to exclude.

// exclude non-default widgets
$include_BasemapToggle    : false;
$include_ColorPicker      : false;
$include_HorizontalSlider : false;
$include_Legend           : false;
$include_RendererSlider   : false;
$include_Ripple           : false;
$include_Search           : false;
$include_Tags             : false;

// import theme base
@import "../base/core";

Notes

ArcGIS API for JavaScript v4.10 made improvements to the way Sass files were structured. These changes were made to improve consistency and make names more semantic (by applying BEM naming convention).

The following lists the main changes that may affect your code:

General

  • Underscores _ have been replaced by dashes -.

Type

  • "text" is now "font" (e.g., $text_size is now $font-size)
  • font size usage terms are now treated as a BEM Element
    • $h1_text_size is now $font-size__h1
    • $body_text_size is now $font-size__body
  • For a smaller font size not related to an element, use $font-size--small
  • Added $base-font-size
    • All font sizes are based on $base-font-size
      • e.g. $font-size__h1: round($base-font-size * 1.428)
  • Font weights
    • $text_weight_normal is now simply $font-weight
    • Use $font-weight__heading for headings ("header" was incorrectly used before)
    • For a bold font weight not related to a heading, use $font-weight__bold

Color (_colorVariables.scss is now _color.scss)

  • Using "font" instead of "text" (e.g., $text_color is now $font-color).
  • Colors for states such as hover and focus are now in the modifier suffix (e.g. $button-color--hover).
  • Color variables are value agnostic because of themes. No use of "light" or "dark" concepts in vars.

Sizes (_sizes.scss)

  • Removed repeated calculations with fractional vars
    • e.g. floor($cap-spacing / 2) can now use $cap-spacing--half
  • Clarified var names for max/min heights based on either
    • internally defined by widget or panel panel-max-height--[size]
    • the height of the view (when a widget is inside a view) view-height--[size]__component-max-height

Animation (_animation.scss)

Animations have been moved to a separate file.

jsapi-styles's People

Contributors

asangma avatar dependabot[bot] avatar driskull avatar jcfranco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jsapi-styles's Issues

Compilation Error

When I try to compile with
sass main.scss theme.css
I get this error:
Error: expected selector. ╷ 173 │ 20%:before, │ ^ ╵ ..\base\_mixins.scss 173:3 loopingProgressBar() ..\base\widgets\_widget.scss 501:3 widget() ..\base\widgets\_widget.scss 566:3 @import ..\base\_core.scss 60:9 @import main.scss 5:9 root stylesheet

Looks like the $selector value in _mixins.scss isn't getting set properly, but I can't see where that variable gets assigned.

EDIT: Looks like line 501 in _Widget.scss calls loopingProgressBar, passing 20% instead of a selector:
@include loopingProgressBar($looping_progress_bar_width);
Removing that line lets it successfully compile.

Multiple maps on same page with different themes - wrap theme in custom selector?

Thank you for this awesome tool. I am not having an issue with the code so much as I have a feature request, or maybe its a need for better documentation, or just some guidance from a subject matter expert about how I can use this tool.

I am trying to create a page that has multiple arcgis maps on it. I want to be able to have different themes for different maps on the same page. Obviously just linking the css files hosted by arcgis won't work. My thought was to use this tool to regenerate the stock themes, but altered. I thought it might be possible to wrap all the scss selectors inside a .dark or .dark-blue scss selector, like this:

.dark {

  // all the scss inside this selector

}

And then wrap my map div in something like this:

<div className="arcgis-map dark">
  <div id="viewDiv" />
</div>

Then I can <link> various css themes in the same html header, and the map wrapper applies the desired style from a single theme.

Or perhaps it would be possible to attach a .dark to all relevant selectors and define the div as

<div id="viewDiv" className="dark">

Though I feel that approach would be trickier as figuring out which selectors to attach a .dark to would be very difficult.

Taking the first approach of using a wrapper, I feel like I would have to manually go through every single scss file that's imported into the base/_core.scss and wrap / alter them myself. Would you agree? This would be a ton of manual footwork. Is there a better way to generate these custom themes? Is there a better way to apply different themes to different maps on the same page in general?

Again, thank you for being awesome.

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.