Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Keypad plugin extends Framework7 with additional custom keyboards

License

NotificationsYou must be signed in to change notification settings

framework7io/framework7-plugin-keypad

Repository files navigation

Framework7 Keypad Plugin

Keypad plugin extends Framework7 with additional custom keyboards. By default it comes with predefinedNumpad andCalculator keyboards, but it also can be used to create custom keyboards with custom buttons.

Installation

Just grab plugin files fromdist/ folder or using npm:

npm install framework7-plugin-keypad

And link them to your app right AFTER Framework7's scripts and styles:

<link rel="stylesheet" href="path/to/framework7.bundle.min.css"><link rel="stylesheet" href="path/to/framework7-keypad.min.css">...<script src="path/to/framework7.bundle.min.js"></script><script src="path/to/framework7-keypad.min.js"></script>

Usage

Install & Enable Plugin

After you included plugin script file, you need to install plugin before you init app:

// install plugin to Framework7Framework7.use(Framework7Keypad);// init appvarapp=newFramework7({  ...})

ES Module

This plugin comes with ready to use ES module:

importFramework7from'framework7';importFramework7Keypadfrom'framework7-plugin-keypad';// install pluginFramework7.use(Framework7Keypad);// init appvarapp=newFramework7({  ...})

API

Plugin extends initiliazedapp instance with new methods:

  • app.keypad.create(parameters) - init Keypad. This method returns initialized Keypad instance.
  • app.keypad.get(keypadEl) - get Keypad instance by HTML element. Method returns initialized Keypad instance.
  • app.keypad.destroy(keypadEl) - destroy Keypad instance

Keypad Instance

Keypad can be created and initialized only using JavaScript. We need to use related App's method:

app.keypad.create(parameters)

Whereparameters -object - object with Keypad parameters. RequiredThis method returns initialized Keypad instance

For example

varmyKeypad=app.keypad.create({inputEl:'#demo-numpad-limited',valueMaxLength:2,dotButton:false});

Keypad Parameters

Let's look on list of all available parameters:

ParameterTypeDefaultDescription
openInstringauto Can beauto,popover (to open keypad in popover) orsheet (to open in sheet modal). In case ofauto will open in sheet modal on small screens and in popover on large screens.
backdropboolean Allows enable/disable backdrop. If not specified then it will be enabled when it opened in Popover.
containerElstring or HTMLElement String with CSS selector or HTMLElement where to place generated Keypad HTML. Use only for inline keypad
containerElstring or HTMLElement String with CSS selector or HTMLElement where to place generated Keypad HTML. Use only for inline keypad
inputElstring or HTMLElement String with CSS selector or HTMLElement with related input element
scrollToInputbooleantrueScroll viewport (page-content) to input when keypad opened
inputReadOnlybooleantrueSets "readonly" attribute on specified input
cssClassstringAdditional CSS class name to be set on keypad modal
toolbarbooleantrueEnables keypad modal toolbar
toolbarCloseTextstringDoneText for Done/Close toolbar button
valuestringInitial Keypad value
formatValuefunction (value) Function to format input value, should return new/formatted string value.value is the current keypad value
typestringnumpadKeypad type, could be 'numpad', 'calculator' or 'custom'
valueMaxLengthnumbernullLimit value by selected number of characters
dotButtonbooleantrueOnly for 'numpad' type. Show or hide "dot" button
dotCharacterstring'.'Dot character symbol. Only for 'numpad' and 'calculator' types
buttonsarray

Array with keypad buttons, by default it is predefined for numpad and calculator, but can be used for custom keypad.

Each button should be presented as object with the following properties:

  • html -string - button inner HTML
  • value -string/number - button value
  • cssClass -string - additional CSS class on button
  • dark -boolean - defines "dark" color button
  • onClick -function (keypad, button) - callback function that will be executed when you click on button

As a reference look at source code to see how buttons defined for Numpad and Calculator

For example:

...buttons: [    {        html:'1',        value: 1,        onClick: function () {            console.log('Button 1 clicked')        }    },    {        html:'A',        value: 'a',    },    ...]
Render functions
renderToolbarfunction (keypad) Function to render toolbar. Must return toolbar HTML string
renderPopoverfunction (keypad) Function to render popover. Must return popover HTML string
renderSheetfunction (keypad) Function to render sheet modal. Must return sheet modal HTML string
renderInlinefunction (keypad) Function to render inline keypad modal. Must return full keypad HTML string

Keypad Methods & Properties

After we initialize Keypad we have its initialized instance in variable (likemyKeypad variable in example above) with helpful methods and properties:

Properties
myKeypad.paramsObject with passed initialization parameters
myKeypad.valueCurrent keypad value
myKeypad.openedtrue if Keypad is currently opened
myKeypad.inlinetrue if Keypad is inline Keypad
myKeypad.$elDom7 instance with Keypad container HTML element
myKeypad.$inputElDom7 instance with Keypad input HTML element
Methods
myKeypad.setValue(value) Set new keypad value.
myKeypad.getValue(value) Get keypad value.
myKeypad.open()Open Keypad
myKeypad.close()Close Keypad
myKeypad.destroy()Destroy Keypad instance and remove all events

Keypad Events

EventTargetArgumentsDescription
changekeypad(keypad, value)Event will be triggered when Keypad value changed
keypadChangeapp(keypad, value)Event will be triggered when Keypad value changed
buttonClickkeypad(keypad, button)Event will be triggered on Keypad button click
keypadButtonClickapp(keypad, button)Event will be triggered on Keypad button click
openkeypad(keypad)Event will be triggered when Keypad item starts its opening animation (modal open transition)
keypadOpenapp(keypad)Event will be triggered when Keypad item starts its opening animation (modal open transition)
openedkeypad(keypad)Event will be triggered after Keypad item completes its opening animation (modal open transition)
keypadOpenedapp(keypad)Event will be triggered after Keypad item completes its opening animation (modal open transition)
closekeypad(keypad)Event will be triggered when Keypad item starts its closing animation (modal close transition)
keypadCloseapp(keypad)Event will be triggered when Keypad item starts its closing animation (modal close transition)
closedkeypad(keypad)Event will be triggered after Keypad item completes its closing animation (modal close transition)
keypadClosedapp(keypad)Event will be triggered after Keypad item completes its closing animation (modal close transition)

Automatic initialization

Such predefined Numpad and Calculator keypads could be initialized automatically. Just use usual inputs but with special type attribute:

<inputtype="numpad"><inputtype="calculator">

Access to Keypad's Instance

If you initialize Keypad as inline Keypad or using automatic initialization, it is still possible to access to Keypad's instance from its HTML container:

varmyKeypad=$$('.keypad-inline')[0].f7Keypad;

CSS Custom Properties

The following CSS custom properties available to customize it:

:root {--f7-keypad-height:260px;--f7-keypad-landscape-height:200px;--f7-keypad-inline-height:200px;--f7-keypad-inline-calc-height:260px;--f7-keypad-popover-width:300px;--f7-keypad-button-bg-color:#fcfcfd;--f7-keypad-button-text-color:#000;--f7-keypad-button-border-color:rgba(0,0,0,0.1);--f7-keypad-button-pressed-bg-color:#bcc0c5;--f7-keypad-button-dark-bg-color:#ddd;--f7-keypad-button-dark-pressed-bg-color:#fcfcfd;--f7-keypad-button-number-font-size:28px;--f7-keypad-button-number-letters-size:11px;--f7-keypad-calc-button-text-color:#fff;--f7-keypad-calc-button-bg-color:#ff9500;--f7-keypad-calc-button-pressed-bg-color:#e0750e;--f7-keypad-calc-button-active-border-color:rgba(0,0,0,0.4);--f7-keypad-calc-button-active-border-width:1px;}

Demo

Plugin comes with demo example to see how it works and looks. To make demo works you need to run in terminal:

$ npm run prod

Contribute

All changes should be done only insrc/ folder. This project usesgulp to build a distributable version.

First you need to install all dependencies:

$ npm install

Then to build plugin's files for testing run:

$ npm run build:dev

If you need a local server while you developing you can run:

$ gulp server

or

$ npm run dev

And working demo will be available athttp://localhost:3000/demo/

Live Preview

https://framework7io.github.io/framework7-plugin-keypad/

About

Keypad plugin extends Framework7 with additional custom keyboards

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors5


    [8]ページ先頭

    ©2009-2025 Movatter.jp