Home Web Front-end JS Tutorial Introduction to JavaScript framework (xmlplus) components (2) Button

Introduction to JavaScript framework (xmlplus) components (2) Button

May 04, 2017 am 10:21 AM
button

xmlplus is a JavaScriptframework used for rapid development of front-end and back-end projects. This article mainly introduces the button of the xmlplus component design series, which has a certain reference value. Interested friends can refer to it

In addition to icons, buttons may be the simplest Component, now let’s take a look at how to define the button group component.

Use native button components

In xmlplus, HTML elements also exist as components. So, you can use button components directly by using button tag or input tag. As shown in the following example:

Example: {
  xml: "<p id=&#39;example&#39;>\
       <button>Default</button>\
       <input type=&#39;submit&#39;>Primary</input>\
     </p>"
}
Copy after login

Although the appearance of native buttons is not so attractive, native buttons are not specially packaged, so they are the fastest to render and the most efficient to execute.

Use Bootstrap style buttons

If your project has no special visual requirements. It's a good idea to use Bootstrap styles to define button components. To use Bootstrap buttons in the traditional way, you would use them like this.

<button type="button" class="btn btn-default">Default</button>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-success">Success</button>
Copy after login

Please observe carefully, do you feel that it gives you more than what you ask for? Not only did you find a lot of type=buttons, you also found a lot of btn. Now here is a component, which is based on Bootstrap style, but it significantly simplifies the use of buttons.

Button: {
  xml: "<button type=&#39;button&#39; class=&#39;btn&#39;/>",
  fun: function (sys, items, opts) {
    this.addClass("btn-" + opts.type);
  }
}
Copy after login

This button component encapsulates the content that needs to be written repeatedly in the original button. When using it, you only need to provide the type attribute to specify the target button, which is more convenient to use. Given below is the way to use the new button component.

<Button type=&#39;default&#39;>Default</Button>
<Button type=&#39;primary&#39;>Primary</Button>
<Button type=&#39;success&#39;>Success</Button>
Copy after login

Buttons with icons

In addition to text, buttons can also have icons attached. Appropriate icons can make the purpose of a button more vivid and intuitive. Here we take EasyUI's icon button as an example to illustrate how to encapsulate and use icon buttons. Let's first take a look at the original use of EasyUI icon buttons.

<p style="padding:5px 0;">
  <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" data-options="iconCls:&#39;icon-add&#39;">Add</a>
  <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" data-options="iconCls:&#39;icon-remove&#39;">Remove</a>
  <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" data-options="iconCls:&#39;icon-save&#39;">Save</a>
</p>
Copy after login

Similar to the encapsulation of Bootstrap buttons in the previous section, the recurring parts are extracted through observation, and the changed parts are displayed in the form of interface. Only the icon type name and text of the above button are variable, so we can make the following design:

Button: {
  xml: "<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton"/>",
  fun: function (sys, items, opts) {
    this.attr("data-options" + "iconCls:&#39;icon-" + opts.type);
  }
}
Copy after login

The following is how to use the new icon, which is obviously much simpler than the original way of use.

<p style="padding:5px 0;">
  <Button type=&#39;add&#39;>Add</Button>
  <Button type=&#39;remove&#39;>Reomve</Button>
  <Button type=&#39;save&#39;>Save</Button>
  <Button type=&#39;cut&#39;>Cut</Button>
</p>
Copy after login

Customize your button component

Using open source frameworks such as Bootstrap and EasyUI can avoid reinventing the wheel. However, when these open source projects don't meet your needs, you need to do it yourself.

For the sake of simplicity, now assuming that the above Bootstrap framework does not exist, then how to design a set of the above buttons? This kind of practice is very meaningful and it will help you draw inferences from one example to another.

Now let us re-observe the button component above. You will find that Bootstrap has designed some style classes that can be combined, among which btn is required by every button. In addition, btn-default, btn-primary, etc. can form combined style classes with btn as needed. Okay, based on this idea, we can design the following component framework.

Button: {
  css: "#btn { 这里是按钮基本的样式 }\
     #default { 这里是default样式 }\
     #primary { 这里是primary样式 }",
  xml: "<button type=&#39;button&#39;/>",
  fun: function (sys, items, opts) {
    this.addClass("#btn #" + opts.type, this);
  }
}
Copy after login

The difference between the above design ideas and the previous direct use of Bootstrap style definition buttons is that the former has already defined each global style class for you, you only need to reference directly. . Here you need to define the relevant style classes within the button component. From an encapsulation perspective, the latter is more cohesive than the former because it does not expose the global class name. Below is a usage example of this component.

Example: {
  xml: "<p id=&#39;example&#39;>\
       <Button type=&#39;default&#39;>Default</Button>\
       <Button type=&#39;primary&#39;>Primary</Button>\
       <Button type=&#39;success&#39;>Success</Button>\
     </p>"
}
Copy after login

Note that for the sake of simplicity, the custom button component here omits the hover and active styles, so it is somewhat different from the Bootstrap button.

This series of articles is based on the xmlplus framework. If you don’t know much about xmlplus, you can visit www.xmlplus.cn. Detailed getting started documentation is available here.

The above is the detailed content of Introduction to JavaScript framework (xmlplus) components (2) Button. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fix Microsoft Teams white screen How to fix Microsoft Teams white screen Apr 17, 2023 pm 05:07 PM

Restart Microsoft Teams If you get a blank screen after launching Teams, a good place to start is to restart the app itself. To close and restart Microsoft Teams: Right-click the Teams icon in the notification area of ​​the taskbar and click Exit from the menu. Restart Microsoft Teams from the Start menu or desktop shortcut and see if it works. Close Microsoft Teams from Task Manager If a basic restart of the Teams process doesn't work, go into Task Manager and end the task. To close Teams from Task Manager, do the following

What is the Windows Security Button? All you need to know What is the Windows Security Button? All you need to know Apr 13, 2023 pm 10:22 PM

What is the Windows Security Button? As the name suggests, Windows Security Button is a security feature that allows you to securely access the login menu and log in to your device using a password. In this case, smartphones are definitely ahead. But Windows portable devices, such as tablets, have begun adding a Windows Security button that's more than just a way to keep unwanted users out. It also provides additional login menu options. Although if you try to find the Windows Security button on your desktop PC or laptop, you might be disappointed. why is that? Tablets vs. PCs The Windows security button is a physical button that exists on tablets

5 Ways to Disable Delivery Optimization Service in Windows 5 Ways to Disable Delivery Optimization Service in Windows May 17, 2023 am 09:31 AM

There are many reasons why you might want to disable the Delivery Optimization service on your Windows computer. However, our readers complained about not knowing the correct steps to follow. This guide discusses how to disable the Delivery Optimization service in a few steps. To learn more about services, you may want to check out our How to open services.msc guide for more information. What does Delivery Optimization Service do? Delivery Optimization Service is an HTTP downloader with cloud hosting solution. It allows Windows devices to download Windows updates, upgrades, applications and other large package files from alternative sources. Additionally, it helps reduce bandwidth consumption by allowing multiple devices in a deployment to download these packages. In addition, Windo

How to restart, force restart, and shut down iPad Mini 6 How to restart, force restart, and shut down iPad Mini 6 Apr 29, 2023 pm 12:19 PM

How to Force Restart iPad Mini 6 Force restarting iPad Mini 6 is done with a series of button presses, and it works like this: Press and release for Volume Up Press and release for Volume Down Press and release the Power/Lock button until you see Apple logo, indicating that the iPad Mini has been force restarted. That’s it. You have force restarted the iPad Mini 6! Force restart is usually used for troubleshooting reasons, such as the iPad Mini freezing, apps freezing, or some other general misbehavior. One thing to note about the procedure for force restarting the 6th generation iPad Mini is that for all other devices that have ultra-thin bezels and use

After rewriting:

How to Fix PS5 Controller Not Recognized on Windows 11 After rewriting: How to Fix PS5 Controller Not Recognized on Windows 11 May 09, 2023 pm 10:16 PM

&lt;h3&gt;What should I know about connecting my PS5 controller? &lt;/h3&gt;&lt;p&gt;As good as the DualSense controller is, there have been reports of the controller not connecting or not being detected. The easiest way to solve this problem is to connect the controller to your PC using an appropriate USB cable. &lt;/p&gt;&lt;p&gt;Some games natively support DualSense. In these cases, you can simply plug in the controller. But this raises other questions, like what if you don't have a USB cable or don't want to use one

How to clear the download history of Microsoft Edge browser? How to clear the download history of Microsoft Edge browser? Apr 21, 2023 am 09:34 AM

&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Click to enter:&lt;/strong&gt;ChatGPT tool plug-in navigation&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Find and delete download history in Edge&lt; /h2&gt;&lt;p&gt;Like other browsers, Edge has a&lt;strong&gt;Download

How to use Vue to implement button countdown effects How to use Vue to implement button countdown effects Sep 21, 2023 pm 02:03 PM

How to use Vue to implement button countdown effects With the increasing popularity of web applications, we often need to use some dynamic effects to improve user experience when users interact with the page. Among them, the countdown effect of the button is a very common and practical effect. This article will introduce how to use the Vue framework to implement button countdown effects and give specific code examples. First, we need to create a Vue component that contains a button and countdown function. In Vue, a component is a reusable Vue instance, and a view will

iOS 17: How to organize iMessage apps in Messages iOS 17: How to organize iMessage apps in Messages Sep 18, 2023 pm 05:25 PM

In iOS 17, Apple not only added several new messaging features, but also tweaked the design of the Messages app to give it a cleaner look. All iMessage apps and tools, such as the camera and photo options, can now be accessed by tapping the "+" button above the keyboard and to the left of the text input field. Clicking the "+" button brings up a menu column with a default order of options. Starting from the top, there's camera, photos, stickers, cash (if available), audio, and location. At the very bottom is a "More" button, which when tapped will reveal any other installed messaging apps (you can also swipe up to reveal this hidden list). How to reorganize your iMessage app You can do this below

See all articles