Code Monkey home page Code Monkey logo

framework7-plugin-keypad's Introduction

Framework7 Keypad Plugin

Keypad plugin extends Framework7 with additional custom keyboards. By default it comes with predefined Numpad and Calculator keyboards, but it also can be used to create custom keyboards with custom buttons.

Installation

Just grab plugin files from dist/ 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 Framework7
Framework7.use(Framework7Keypad);

// init app
var app = new Framework7({
  ...
})

ES Module

This plugin comes with ready to use ES module:

import Framework7 from 'framework7';
import Framework7Keypad from 'framework7-plugin-keypad';

// install plugin
Framework7.use(Framework7Keypad);

// init app
var app = new Framework7({
  ...
})

API

Plugin extends initiliazed app 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)

Where parameters - object - object with Keypad parameters. Required This method returns initialized Keypad instance

For example

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

Keypad Parameters

Let's look on list of all available parameters:

Parameter Type Default Description
openIn string auto Can be auto, popover (to open keypad in popover) or sheet (to open in sheet modal). In case of auto will open in sheet modal on small screens and in popover on large screens.
backdrop boolean Allows enable/disable backdrop. If not specified then it will be enabled when it opened in Popover.
containerEl string or HTMLElement String with CSS selector or HTMLElement where to place generated Keypad HTML. Use only for inline keypad
containerEl string or HTMLElement String with CSS selector or HTMLElement where to place generated Keypad HTML. Use only for inline keypad
inputEl string or HTMLElement String with CSS selector or HTMLElement with related input element
scrollToInput boolean true Scroll viewport (page-content) to input when keypad opened
inputReadOnly boolean true Sets "readonly" attribute on specified input
cssClass string Additional CSS class name to be set on keypad modal
toolbar boolean true Enables keypad modal toolbar
toolbarCloseText string Done Text for Done/Close toolbar button
value string Initial Keypad value
formatValue function (value) Function to format input value, should return new/formatted string value. value is the current keypad value
type string numpad Keypad type, could be 'numpad', 'calculator' or 'custom'
valueMaxLength number null Limit value by selected number of characters
dotButton boolean true Only for 'numpad' type. Show or hide "dot" button
dotCharacter string '.' Dot character symbol. Only for 'numpad' and 'calculator' types
buttons array

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
renderToolbar function (keypad) Function to render toolbar. Must return toolbar HTML string
renderPopover function (keypad) Function to render popover. Must return popover HTML string
renderSheet function (keypad) Function to render sheet modal. Must return sheet modal HTML string
renderInline function (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 (like myKeypad variable in example above) with helpful methods and properties:

Properties
myKeypad.params Object with passed initialization parameters
myKeypad.value Current keypad value
myKeypad.opened true if Keypad is currently opened
myKeypad.inline true if Keypad is inline Keypad
myKeypad.$el Dom7 instance with Keypad container HTML element
myKeypad.$inputEl Dom7 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

Event Target Arguments Description
change keypad (keypad, value) Event will be triggered when Keypad value changed
keypadChange app (keypad, value) Event will be triggered when Keypad value changed
buttonClick keypad (keypad, button) Event will be triggered on Keypad button click
keypadButtonClick app (keypad, button) Event will be triggered on Keypad button click
open keypad (keypad) Event will be triggered when Keypad item starts its opening animation (modal open transition)
keypadOpen app (keypad) Event will be triggered when Keypad item starts its opening animation (modal open transition)
opened keypad (keypad) Event will be triggered after Keypad item completes its opening animation (modal open transition)
keypadOpened app (keypad) Event will be triggered after Keypad item completes its opening animation (modal open transition)
close keypad (keypad) Event will be triggered when Keypad item starts its closing animation (modal close transition)
keypadClose app (keypad) Event will be triggered when Keypad item starts its closing animation (modal close transition)
closed keypad (keypad) Event will be triggered after Keypad item completes its closing animation (modal close transition)
keypadClosed app (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:

<input type="numpad">
<input type="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:

var myKeypad = $$('.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 in src/ folder. This project uses gulp 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 at http://localhost:3000/demo/

Live Preview

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

framework7-plugin-keypad's People

Contributors

dann2012 avatar ionas avatar ju2ender avatar nolimits4web avatar shastox avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

framework7-plugin-keypad's Issues

Click sound support?

Viewing the demo there doesn't appear to be click sounds when pressing the keypad buttons. Is there a way to enable this?

Unable to Reset Value

Could you please share the code snippet to reset the textbox value programmatically? Actually, i am using type "numpad" in html to create keypad.

Thanks

Module Import issue with vite

On the latest f7 Vite is the only bundler available and throws this error while build:

node_modules/vite/dist/node/chunks/dep-36bf480c.js:43807:10: error: [plugin: vite:dep-scan] Failed to resolve entry for package "framework7-plugin-keypad". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "framework7-plugin-keypad". The package may have incorrect main/module/exports specified in its package.json.

Upon Inspect I came to this stacktrace:
src/js/app.js:4:29: note: The plugin "vite:dep-scan" was triggered by this import 4 │ import Framework7Keypad from 'framework7-plugin-keypad';

I checked the package.json file for the plugin and everything looks ok to me. Any suggestions?

custom keys - full keyboard

I'd need a full keyboard and supplied all keys as props, but only the first 12 keys are rendered, because the layout is fix. What's the point in supplying custom keys, if you assume keypad?

The delete key should have an auto-repeat capability to delete long numbers quickly

The delete key in the keypad should have an auto-repeat capability to allow the user to efficiently delete a long number quickly and efficiently. It should behave while the key is being pressed and after a delay.

The native delete key on iOS will delete the first character on the initial press and then start repeating the delete after an initial delay of about 100ms. Each character is deleted at a rate of about 50ms. These numbers are just ballpark and would have to be tweaked.

Adding Keypad plugin to ember project

I already added Framework7 to my Ember cli project. But I can not make Keypad works. My initialize file:

export function initialize(container, application) {
  var f7 = new window.Framework7();

  application.register('f7:main', f7, { instantiate: false });
  application.inject('route', 'f7', 'f7:main');
  application.inject('controller', 'f7', 'f7:main');
  application.inject('component', 'f7', 'f7:main');
  application.inject('view', 'f7', 'f7:main');
}

export default {
  name: 'framework7-service',
  initialize: initialize
};

I included Keypad js and css file in Brocfile.js:

app.import({
  development: 'bower_components/framework7-keypad/dist/framework7.keypad.css',
  production: 'bower_components/framework7-keypad/dist/framework7.keypad.min.css'
});

app.import({
  development: 'bower_components/framework7-keypad/dist/framework7.keypad.js',
  production: 'bower_components/framework7-keypad/dist/framework7.keypad.min.js'
});

When I use <input type="numpad"> it's not working, nothing happen.
I figure out that when running the code: var f7 = new window.Framework7();, the plugin is not found(or hooked)

Numeric only 1,2,3 on Android devices

Hi,

I know it is probably not supported, but maybe there's a quick fix for this. On Android devices, only the numbers 1,2,3 are visible when using numeric. They are fully functional, but i miss the other 6 buttons. Tried to change some z-index values in the css file, but none helps. Maybe you know how this could be fixed.

Thanks!

Bower issue

When install the package using bower (bower install framework7-keypad --save), The name of the package in bower.js file should be "Framework7-Keypad": "framework7-keypad#^1.0.3". I'm having a problem because bower automacally generate the name: "Framework7 Keypad": "framework7-keypad#^1.0.3" (no dash), so that i can not update the package using bower update.

Do you support react?

Maybe this is obvious, but any way to make it work with React framework7 plugin?

Thanks,
Serkan

Request: Ability to disable a button based on current value

I would like to disable buttons programmatically depending on the current value. For example, on the calculator, some of the operations should be disabled when there is no left-value. Or for another example, I would like to only accept inputs between 1-37, and so when the user inputs 3, I would like to disable buttons 8 and 9.

Framework7 Keypad events listener not working

I have a keypad

var keypad = app.keypad.create({
    inputEl: '#input',
    on: {
        change: function (keypad, value) {
            console.log(keypad, value);
        }
    }
});

change event is NOT called when value is changed (this is same for all other events like open close etc…)

Tried

keypad .on("change",  (keypad, value) {
        console.log(keypad, value);
})

i get Uncaught (in promise) Error: TypeError: Cannot read property 'change' of undefined

Any Ideas?

Needs a caret

The cursor position is not accounted, nor displayed (the "input-focused" class is removed from the input even when inputReadOnly is set to false), for this widget e.g.
"12|34"
then press delete on the keypad should result in
"1|34" rather than "123"

In the iOS version the user cannot tell which input is active. In Android it's more clear but still needs a caret for more user feedback.

Framework7 keypad + swipe incompatibility

As title, when a keypad is within a swipe it won't work, any ideas?

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide" style="text-align:center">
            <h3>Product name</h3>
            <div class="range-slider"><input type="range" min="0" value="" step="1" onchange="$$(this).parent().parent().find('span').html(this.value);" oninput="$$(this).parent().parent().find('input').val(this.value);"></div>
            <div class="list-block">
                <ul>
                    <li><div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">Qtd</div>
                            <div class="item-input">
                                <input type="text" class="kpNumpad">
                            </div>
                        </div>
                    </div></li>
                </ul>
            </div>
            <img  src="img/temp/img01-mobile-md.jpg" style="max-height: 45vh;">
        </div>
    </div>
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
</div>
myApp.keypad({ 'input': '.kpNumpad', 'dotButton': true, 'toolbarCloseText': 'Fechar', 'toolbarTemplate': '' });

myApp.swiper('.swiper-container',{
    'onlyExternal': true,
    'nextButton': '.swiper-button-next',
    'prevButton': '.swiper-button-prev',
    'speed':  600,
    'loop': true,
    'effect': 'slide' //-- slide, coverflow, flip
});

No matter the order if swiper or keypad is called first, none of them work, debugging inside a browser, the div of keypad is created but don't show, and input becomes unclicable.

Cannot read property 'name' of undefined

Hi
I am trying to use kepad for v5 as follows:

import Framework7 , {Template7} from 'framework7/framework7.esm.bundle.js';
Framework7.use(Framework7Keypad);

var app = new Framework7({
......

but app won't start and always gives:

class.js:150 Uncaught TypeError: Cannot read property 'name' of undefined
    at Function.installModule (class.js:150)

What could be the reason ?
thanks

Адаптация плагина для 4й версии F7

Этот замечательный плагин не работает нормально в 4й версии:
если на телефоне (именно на телефоне) набирать быстро цифры, то будут огромные задержки. Решается включением отключенного Fast Click:

    touch: {
        fastClicks: true,
    },

В 5й версии, с выпиленным fast click, я так понимаю плагин вообще не совместим. Если можно, было бы здорово его адаптировать под 5ку :)

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.