7.7.1 • Published 1 year ago

@justeat/f-mega-modal v7.7.1

Weekly downloads
100
License
Apache-2.0
Repository
github
Last release
1 year ago

f-mega-modal

A Vue.js modal component


npm version CircleCI


Usage

Installation

Install the module using NPM or Yarn:

yarn add @justeat/f-mega-modal
npm install @justeat/f-mega-modal

The package also has dependencies that need to be installed by consuming components/applications:

DependencyCommand to installStyles to include
f-buttonyarn add @justeat/f-buttonimport '@justeat/f-button/dist/f-button.css';

Vue Applications

You can import it in your Vue SFC like this (please note that styles have to be imported separately):

import MegaModal from '@justeat/f-mega-modal';
import '@justeat/f-mega-modal/dist/f-mega-modal.css';

export default {
    components: {
        MegaModal
    }
}

If you are using Webpack, you can import the component dynamically to separate the mega-modal bundle from the main bundle.client.js:

import '@justeat/f-mega-modal/dist/f-mega-modal.css';

export default {
    components: {
// …
        MegaModal: () => import(/* webpackChunkName: "mega-modal" */ '@justeat/f-mega-modal')
    }
}

Non-Vue Applications

This module can be ran as a micro front-end for applications that don't make use of the Vue framework.

The following rudimentary example can be used as a guide for implementing this component in an existing static application:

<!doctype html>
<html lang="en">
<head>
    <title>Mega Modal Example</title>
    <link rel="stylesheet" href="https://unpkg.com/@justeat/f-mega-modal/dist/f-mega-modal.css">
</head>
<body>
    <div data-app>
        <mega-modal is-open>
          <p>Modal content</p>
        </mega-modal>
    </div>
    <script src="https://unpkg.com/vue@2.6.11/dist/vue.js"></script>
    <script src="https://unpkg.com/@justeat/f-mega-modal/dist/f-mega-modal.umd.min.js"></script>
    <script>
        (function() {
            if (typeof Vue === 'undefined') return null;

            Vue.config.devtools = false;
            Vue.config.productionTip = false;

            return new Vue({
                el: '[data-app]'
            });
    	})();
    </script>
</body>
</html>

Configuration

Props

f-mega-modal has a number of props that allow you to customise its functionality.

The props that can be defined are as follows:

PropTypeDefaultDescription
is-openBooleanfalseSets the modal to open or closed state.
is-narrowBooleanfalseUse the narrow visual style.
is-wideBooleanfalseUse the wide visual style.
is-flushBooleanfalseRemoves passing around the modal content.
is-full-heightBooleanfalseSets the modal content to full height of the screen.Note this only applies to small screen devices.
is-scrollableBooleanfalseMakes the modal content scrollable.
is-close-fixedBooleanfalseSets the modal close button position to fixed.
is-positioned-bottomBooleanfalseSets the modal position to the bottom of the viewport for all screen widths.
has-overlayBooleantrueControls whether or not to display an overlay behind the modal.
close-button-styleStringcrossControls the style of the button. Accepts cross & chevron.
close-on-blurBooleantrueControls whether or not to close the modal when the user clicks outside of the modal.
close-button-copyString"Close modal"Sets the hidden text value for the close button which is used by screen-readers.
titleString''When set, will add a title to the top of the component. If you need to define a custom heading, ignore this prop.
titleHtmlTagStringh3Sets the tag for the component's title.Allowed values are h1, h2, h3, and h4
isModeRightToLeftBooleanfalseControls whether or not to display the modal elements in a right to left direction.

CSS Classes

The modal has its own styles which are scoped to the component using CSS modules to prevent conflicts with existing styles on the page.

In addition to this, the modal exposes some classes which you can target in your application.

ClassDescription
c-megaModalCan be used to target the modal wrapper element.
c-megaModal-contentCan be used to target the modal content element.
c-megaModal-content--visibleCan be used to target the modal content element when it is visible.
c-megaModal-documentCan be used to target the modal document element.
c-megaModal-document--scrollableCan be used to target the modal document element when it is scrollable.
c-megaModal-closeBtnCan be used to target the modal close button element.

The modal is also using utility css styles from fozzie package. You need to make sure to @include trumps-utilities(); mixin to your application styles if you use beta version of fozzie package (>= v5.0.0-beta.0). If you are using main version (v4.X.X) styles should come out of the box.

Events

EventDescription
openThis event is emitted when the modal is opened.
closeThis event is emitted when the modal is closed.

You can add event listeners for these like so

<template>
  <mega-modal
    @open="onModalOpen"
    @close="onModalClose">
    <p>Modal content</p>
  </mega-modal>
</template>

<script>
export default {
  methods: {
    onModalOpen () {
      // Do stuff here
    },

    onModalClose () {
      // Do stuff here
    }
  }
}
</script>

Development

Start by cloning the repository and installing the required dependencies:

$ git clone git@github.com:justeat/fozzie-components.git
$ cd fozzie-components
$ yarn

Change directory to the f-mega-modal package:

$ cd packages/components/molecules/f-mega-modal

Testing

Unit, Integration and Contract

To test all components, run from root directory. To test only f-form-field, run from the ./fozzie-components/packages/f-form-field directory.

yarn test

Running storybook

Storybook can be used to develop new and existing components.

To start storybook:

From the root directory run:

$ yarn storybook:serve

This will build and serve storybook at http://localhost:6006.

7.7.1

1 year ago

7.7.0

1 year ago

7.6.0

2 years ago

7.5.0

2 years ago

7.4.1

2 years ago

7.4.0

2 years ago

7.3.0

2 years ago

7.2.1

3 years ago

6.0.0

3 years ago

7.0.0

3 years ago

7.2.0

3 years ago

7.1.0

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.1.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.2.0

3 years ago

4.0.2

3 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.12.1

4 years ago

1.0.0-beta.0

4 years ago

0.12.0

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.4.0

4 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago