github.com-calebporzio-project-x_-_2019-12-02_04-46-38

github.com-calebporzio-project-x_-_2019-12-02_04-46-38

Posted by

Download
ITEM TILE – File Size: 11.8K

A simple tool for composing javascript behavior in your markup.

Project X

Project X offers you the reactive and declarative nature of big frameworks like Vue or React at a much lower cost.

You get to keep your DOM, and sprinkle in behavior as you see fit.

Think of it like Tailwind for JavaScript.

Note: This tool’s syntax is almost entirely borrowed from Vue.js. I am forever grateful for the gift that it is to the web.

Install

Add the following script to the end of your section.“`html

“`

Use

These examples use the .hidden class from Tailwind. If you aren’t using tailwind, just add .hidden { display: none; } to your stylesheet.

Dropdown/Modal“`html

Open Dropdown

“`

Tabs“`html

Foo Bar

“`

Learn

There are 7 directives available to you:

| Directive| — || x-data || x-bind || x-on || x-model || x-text || x-ref || x-cloak |

Here’s how they each work:


x-data

Example:

...

Structure:

...

x-data declares a new component scope. It tells the framework to initialize a new component with the following data object.

Think of it like the data property of a Vue component.


x-bind

Example:

Structure:

x-bind sets the value of an attribute to the result of a JavaScript expression. The expression has access to all the keys of the component’s data object, and will update every-time it’s data is updated.

Note: attribute bindings ONLY update when their dependancies update. The framework is smart enough to observe data changes and detect which bindings care about them.

x-bind for class attributes

x-bind behaves a little differently when binding to the class attribute.

For classes, you pass in an object who’s keys are class names, and values are boolean expressions to determine if those class names are applied or not.

For example:

In this example, the “hidden” class will only be applied when the value of the foo data attribute is true.


x-on

Example:

Structure:

x-on attaches an event listener to the element it’s declared on. When that event is emitted, the JavaScript expression set as it’s value is executed.

If any data is modified in the expression, other element attributes “bound” to this data, will be updated.

.away modifier

Example:

When the .away modifier is present, the event handler will only be executed when the event originates from a source other than itself, or its children.

This is useful for hiding dropdowns and modals when a user clicks away from them.

.prevent modifierExample:

Adding .prevent to an event listener will call preventDefault on the triggered event. In the above example, this means the checkbox wouldn’t actually get checked when a user clicks on it.

.stop modifierExample:

Adding .stop to an event listener will call stopPropagation on the triggered event. In the above example, this means the “click” event won’t bubble from the button to the outer

. Or in other words, when a user clicks the button, foo won't be set to 'bar'.

x-model

Example:

Structure:

x-model adds "two-way data binding" to an element. In other words, the value of the input element will be kept in sync with the value of the data item of the component.

Note: x-model is smart enough to detect changes on text inputs, checkboxes, radio buttons, textareas, selects, and multiple selects. It should behave how Vue would in those scenarios.

x-text

Example:

Structure:

x-text works similarly to x-bind, except instead of updating the value of an attribute, it will update the innerText of an element.

x-ref

Example:

Structure:

x-ref provides a convenient way to retrieve raw DOM elements out of your component. By setting an x-ref attribute on an element, you are making it available to all event handlers inside an object called $refs.

This is a helpful alternative to setting ids and using document.querySelector all over the place.

x-cloak

Example:

x-cloak attributes are removed from elements when Project-X initializes. This is useful for hiding pre-initialized DOM. It's typical to add the following global style for this to work:

html


To restore the repository download the bundle

wget https://archive.org/download/github.com-calebporzio-project-x_-_2019-12-02_04-46-38/calebporzio-project-x_-_2019-12-02_04-46-38.bundle

and run:

 git clone calebporzio-project-x_-_2019-12-02_04-46-38.bundle 

Source: https://github.com/calebporzio/project-x
Uploader: calebporzio
Upload date: 2019-12-02