2.1.150 • Published 16 hours ago

easy-navigation v2.1.150

Weekly downloads
-
License
MIT, Anti-996
Repository
github
Last release
16 hours ago

Easy Navigation

A responsive accordion and associated navigation.

There is an accordion element, which can take an array of arrays of articles, together with a navigation element. The two can be used in tandem or independently. They are responsive in the sense that they can be easily styled to work together with only one of them showing at any one time. They can also be made to respond to changes in the browser's address bar.

JSX support

There is now support for JSX in the form of Juxtapose. What this means is that Easy will now help you with the architecture of your large application. So although Easy elements will continue to work standalone, their use with Juxtapose is recommended.

Related projects

Installation

You can install Easy Layout with npm:

npm install easy-navigation

You can also clone the repository with Git...

git clone https://github.com/djalbat/easy-navigation.git

...and then install the dependencies with npm from within the project's root directory:

npm install

Example

There is a small development server that can be run from within the project's directory with the following command:

npm start

The example will then be available at the following URL:

http://localhost:8888

The source for the example can be found in the src/example.js file and correspondingsrc/example folder. You are encouraged to try the example whilst reading what follows. You can rebuild it on the fly with the following command:

npm run watch-debug

The development server will reload the page whenever you make changes.

One last thing to bear in mind is that this package is included by way of a relative rather than a package import. If you are importing it into your own application, however, you should use the standard package import.

Usage

A view class that utilises both the accordion and associated navigation is shown below:

import Accordion from "./accordion";
import ArticlesArray from "./articlesArray";
import AccordionNavigation from "./navigation/accordion";

class View extends Element {
  showArticle(uri, instantly) {
    this.updateAccordion(uri, instantly);
    this.updateAccordionNavigation(uri);
  }

  childElements() {
    const showArticle = this.showArticle.bind(this);
    
    return ([

      <Accordion ArticlesArray={ArticlesArray} showArticle={showArticle} />,
      <AccordionNavigation ArticlesArray={ArticlesArray} showArticle={showArticle} />

    ]);
  }

  initialise() {
    this.assignContext();
  }

  static tagName = "div";

  static defaultProperties = {
    className: "view"
  };
}

You must pass a showArticles() method to both the accordion and associated navigation as well as an array of arrays of articles. Note that local instances of both have been used in order that custom styles can be applied. This is explained in greater detail in the section on styles that comes next.

Calling the assignContext() method in the view's initialise() method makes the updateAccordion() and updateAccordionNavigation() methods available to the view and it is these methods that are called from its showArticle() method. Note that the updateAccordion() method takes optional instantly and callback arguments. If set to true the instantly argument will force the acoordion to show articles instantly, that is, with no animations. The callback argument allows a callback function to be provided that is invoked when the animation completes. If the instantly argument has been set to true, this callback is called immediately.

An example array of arrays of articles is shown below:

const ArticlesArray = [ ///
  [ HomeArticle, LinksArticle, ButtonsArticle, HeadingsArticle ],
  CodesArticle,
  InputsArticle,
  SectionsArticle
];

export default ArticlesArray;

In fact not all the elements of the outermost array need to be arrays, single articles are coerced into arrays automatically. For genuine arrays the first element is taken as the main article in that it's title is shown in the accordion and associated navigation buttons. There is no second level navigation to enable the other articles to be shown. However, if they are shown by means of links or whatever, both the accordion and associated navigation will respond by enabling the button corresponding to the first article in the array, thus allowing the user to navigate back to it.

The articles provided must have title, uri andpath static properties. For example:

import Article from"/../article";

import { buttonsURI } from "../uris";
import { buttonsPath } from "../paths";

export default class ButtonsArticle extends Article {
  childElements() {
    return (

      <div>
        <h1>
          Buttons
        </h1>
      </div>

    );
  }

  static uri = buttonsURI;

  static path = buttonsPath;

  static title = "Buttons";

  static defaultProperties = {
    className: "buttons"
  };
}

Note that a predefined Article class has been extended here, see the styles section below.

Paths are used to match URIs and should be regular expressions. This means that URIs that include, say, dynamic identifiers, can be matched.

Styles

The way to make the accordion and associated navigation work in tandem responsively is to hide the accordion's buttons as the screen widens and hide the navigation entirely as the screen narrows. By only hiding the accordion's bottons, its child articles remain visible and this gives the desired effect.

Here is some example styling for the view:

export default withStyle(View)`

  padding: 4rem;

  display: block;
  
  @media (min-width: 800px) {

    display: grid;
    
    column-gap: 2rem;
    grid-template-rows: 1fr;
    grid-template-areas: "accordion-navigation accordion";
    grid-template-columns: 20rem auto;

  }

`;

Note the use of the grid template areas. These are not present on the accordion and associated navigation by default and must be added with custom styles. Here is an example of styling the associated navigation:

import { AccordionNavigation } from "easy-navigation";

export default withStyle(AccordionNavigation)`

  grid-area: accordion-navigation;
  
  display: none;
  
  @media (min-width: 800px) {
  
    display: block;
  
  }

`;

Note that as well as the grid-arae property the navigation's visibility is toggled as the screen width changes.

Before looking at the accordion, note that you may also wish to create an Article class in order to set the appropriate whitespace around the articles:

import { Element } from "easy";

class Article extends Element {
  static tagName = "article";
}

export default withStyle(Article)`

  padding: 2rem;
  
  :not(:first-of-type) {

    border-top: 1px solid black;
    
  }

  @media (min-width: 800px) {
  
    padding: 0;
    
    :not(:first-of-type) {
  
      border-top: none;
      
    }
  
  }
`;

Finally, the accordion's buttons can be made to be responsive with another media query:

import { AccordionButton } from "easy=accordion";

export default withStyle(AccordionButton)`

  @media (min-width: 800px) {

    display: none;

  }

`;

The accordion must be appraised of this new button and this is done in two stages. First, the AccordionItem class must be overridden in the following manner...

import { AccordionItem } from "easy-navigation";

import AccordionButton from "../button/accordion";

export default class extends AccordionItem {
  static AccordionButton = AccordionButton;
}

...and then the accordion must be appraised of this new item:

import { Accordion } from "easy-navigation";

import AccordionItem from "./item/accordion";

export default withStyle(class extends Accordion {
  static AccordionItem = AccordionItem;
})`

  grid-area: accordion;

  border: 1px solid black;
  
  @media (min-width: 800px) {
  
    border: none;
  
  }

`;

Note that in this instance it has also been given a responsive border.

It has already been mentioned but it is worth repeating that only the accordion's buttons need to be hidden as the screen widens whilst its child articles remain in use, so to speak. In this way responsiveness is acheived without the need to duplicate content.

Building

Automation is done with npm scripts, have a look at the package.json file. The pertinent commands are:

npm run build-debug
npm run watch-debug

Contact

  • james.smith@djalbat.com
2.1.150

16 hours ago

2.1.149

18 hours ago

2.1.147

2 days ago

2.1.148

2 days ago

2.1.146

11 days ago

2.1.145

16 days ago

2.1.144

27 days ago

2.1.143

28 days ago

2.1.142

30 days ago

2.1.141

1 month ago

2.1.140

1 month ago

2.1.138

1 month ago

2.1.139

1 month ago

2.1.134

1 month ago

2.1.133

1 month ago

2.1.136

1 month ago

2.1.135

1 month ago

2.1.137

1 month ago

2.1.132

2 months ago

2.1.130

2 months ago

2.1.131

2 months ago

2.1.129

2 months ago

2.1.128

2 months ago

2.1.127

2 months ago

2.1.126

2 months ago

2.1.125

2 months ago

2.1.124

2 months ago

2.1.123

2 months ago

2.1.119

3 months ago

2.1.121

3 months ago

2.1.120

3 months ago

2.1.122

3 months ago

2.1.112

3 months ago

2.1.114

3 months ago

2.1.113

3 months ago

2.1.116

3 months ago

2.1.115

3 months ago

2.1.118

3 months ago

2.1.117

3 months ago

2.1.110

3 months ago

2.1.111

3 months ago

2.1.109

3 months ago

2.1.108

3 months ago

2.1.107

3 months ago

2.1.106

3 months ago

2.1.105

3 months ago

2.1.103

3 months ago

2.1.104

3 months ago

2.1.102

4 months ago

2.1.101

4 months ago

2.1.99

4 months ago

2.1.100

4 months ago

2.1.98

4 months ago

2.1.97

4 months ago

2.1.96

4 months ago

2.1.95

4 months ago

2.1.94

4 months ago

2.1.92

4 months ago

2.1.93

4 months ago

2.1.91

4 months ago

2.1.89

4 months ago

2.1.87

4 months ago

2.1.88

4 months ago

2.1.86

4 months ago

2.1.90

4 months ago

2.1.85

5 months ago

2.1.84

5 months ago

2.1.83

6 months ago

2.1.81

7 months ago

2.1.82

7 months ago

2.1.80

7 months ago

2.1.78

8 months ago

2.1.79

8 months ago

2.1.76

8 months ago

2.1.77

8 months ago

2.1.74

8 months ago

2.1.75

8 months ago

2.1.72

8 months ago

2.1.73

8 months ago

2.1.70

8 months ago

2.1.71

8 months ago

2.1.69

9 months ago

2.1.67

9 months ago

2.1.68

9 months ago

2.1.65

9 months ago

2.1.66

9 months ago

2.1.63

12 months ago

2.1.64

12 months ago

2.1.62

12 months ago

2.1.58

1 year ago

2.1.59

1 year ago

2.1.56

1 year ago

2.1.57

1 year ago

2.1.54

1 year ago

2.1.55

1 year ago

2.1.52

1 year ago

2.1.53

1 year ago

2.1.51

1 year ago

2.1.61

1 year ago

2.1.60

1 year ago

2.1.49

1 year ago

2.1.48

1 year ago

2.1.50

1 year ago

2.1.47

1 year ago

2.1.39

2 years ago

2.1.45

1 year ago

2.1.46

1 year ago

2.1.43

1 year ago

2.1.44

1 year ago

2.1.41

1 year ago

2.1.42

1 year ago

2.1.40

1 year ago

2.1.38

2 years ago

2.1.36

2 years ago

2.1.37

2 years ago

2.1.34

2 years ago

2.1.35

2 years ago

2.1.33

2 years ago

2.1.31

2 years ago

2.1.30

2 years ago

2.1.9

2 years ago

2.1.16

2 years ago

2.1.17

2 years ago

2.1.14

2 years ago

2.1.15

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.18

2 years ago

2.1.19

2 years ago

2.1.27

2 years ago

2.1.28

2 years ago

2.1.25

2 years ago

2.1.26

2 years ago

2.1.23

2 years ago

2.1.24

2 years ago

2.1.21

2 years ago

2.1.22

2 years ago

2.1.29

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.7

2 years ago

2.0.30

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.0.28

2 years ago

2.0.29

2 years ago

2.0.26

2 years ago

2.0.27

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.15

2 years ago

2.0.16

2 years ago

2.0.13

2 years ago

2.0.14

2 years ago

2.0.11

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

1.0.48

2 years ago

1.0.49

2 years ago

2.0.19

2 years ago

2.0.17

2 years ago

2.0.18

2 years ago

2.0.24

2 years ago

2.0.25

2 years ago

2.0.22

2 years ago

1.0.51

2 years ago

2.0.23

2 years ago

1.0.50

2 years ago

2.0.20

2 years ago

2.0.21

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.29

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.37

2 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.19

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago