Coder Social home page Coder Social logo

intelligentraji / control.ts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from teleuzi/control.ts

0.0 0.0 0.0 1.27 MB

control.ts is a lightweight (<1kb) and versatile UI library for building modern web applications with ease.

Shell 0.09% JavaScript 1.74% TypeScript 84.17% CSS 2.21% HTML 0.21% Dockerfile 0.51% SCSS 4.44% MDX 6.63%

control.ts's Introduction

control.ts - Control your code with ease

control.ts is a lightweight (<1kb) and versatile UI library for building modern web applications with ease. With its intuitive syntax and powerful features, сontrol.ts simplifies the process of creating dynamic user interfaces.

Features

  • Easy-to-Use API: сontrol.ts provides a familiar interface, with classes and functions named after HTML elements, making it simple to create and manipulate UI components.

  • Modular Design: Each component is designed to be modular, allowing for easy customization and integration into existing projects.

  • TypeScript Support: Built with TypeScript, сontrol.ts offers type safety and enhanced code readability, making it a great choice for large-scale projects.

Installation

To install control.ts, simply run:

npm install @control.ts/min

// or

pnpm add @control.ts/min

// or

yarn add @control.ts/min

Getting Started

Using сontrol.ts is straightforward. Here's a basic example of creating a menu with links:

import { nav, ul, li, a, mount } from '@control.ts/min';

const links = [
  { href: '/', text: 'Home' },
  { href: '/about', text: 'About' },
  { href: '/contact', text: 'Contact' },
];

const menu = nav(
  {
    className: 'nav-menu',
  },
  ul(
    { className: 'menu' },
    ...links.map((link) => li({ className: 'menu-item' }, a({ href: link.href, txt: link.text }))),
  ),
);

const app = document.getElementById('app');
mount(app!, menu);

Preact Signals Integration

control.ts also seamlessly integrates with Preact Signals in @control.ts/signals standalone package, allowing for efficient handling of UI events and state management.

The provided TypeScript code snippet demonstrates the implementation of a button component using control.ts and signals. The component utilizes signals for dynamic behavior and styling, providing a reactive and modular approach to building UI elements.

import type { Signalize } from '@control.ts/signals';
import { $$, button$, getValue$ } from '@control.ts/signals';

import styles from './button.module.scss';

interface Props {
  txt: string;
  onClick?: () => void;
  className?: Signalize<string>;
}

export const Button = ({ txt, onClick, className }: Props) =>
  button$({
    className: $$(() => `${styles.button} ${getValue$(className) || ''}`),
    txt,
    onclick: (e: Event) => {
      e.preventDefault();
      onClick?.();
    },
  });

In this example:

  • The Button component is defined, accepting props such as text (txt), an optional click event handler (onClick), and a dynamic class name (className).
  • The className is defined as a Signalize<string>, indicating that it can be a Signal with string value.
  • Inside the Button component, the button$ function from control.ts is used to create a button element. It is a wrapper of the BaseComponent with button tagName.
  • The className for the button is computed dynamically using $$, a computed signal that combines styles from the css module with any additional classes provided through the className prop.
  • The getValue$ retrieves the current value from a signal or a non-signal input and ensures that the latest value is obtained.

License

сontrol.ts is licensed under the MIT License.

Contact

Have questions or need support? Feel free to reach out to us at support.


control.ts's People

Contributors

teleuzi avatar github-actions[bot] avatar intelligentraji avatar vktrenokh avatar thunderflight avatar dependabot[bot] avatar

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.