All Projects → wtnbass → fuco

wtnbass / fuco

Licence: MIT license
Functional Component like React, but for Web Components.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fuco

pattern-library
AXA CH UI component library. Please share, comment, create issues and work with us!
Stars: ✭ 103 (+45.07%)
Mutual labels:  webcomponents, lit-html
bce.design
minimal magic, minimal tooling, essential dependencies, high productivity, no transpilations and no migrations. The Web Components starter ships with integrated lit-html, redux-toolkit and vaadin router components.
Stars: ✭ 67 (-5.63%)
Mutual labels:  webcomponents, lit-html
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (-50.7%)
Mutual labels:  webcomponents, lit-html
lit-components
Moved to https://github.com/vaadin/component-mixins
Stars: ✭ 59 (-16.9%)
Mutual labels:  webcomponents, lit-html
highcharts-webcomponent
Highcharts Web Component usable with any Framework
Stars: ✭ 21 (-70.42%)
Mutual labels:  webcomponents, lit-html
Wired Elements
Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.
Stars: ✭ 8,848 (+12361.97%)
Mutual labels:  webcomponents, lit-html
create-evergreen-app
Get up and running with an evergreen web application development stack designed by, and for, today's modern web.
Stars: ✭ 16 (-77.46%)
Mutual labels:  webcomponents, lit-html
wheat-ui
Web Components 组件库;拍平框架差异
Stars: ✭ 17 (-76.06%)
Mutual labels:  webcomponents, lit-html
redux-connect-element
Redux HTMLElement Connector
Stars: ✭ 16 (-77.46%)
Mutual labels:  webcomponents, lit-html
polymerx-cli
⚡ Unlock the power of Polymer 3, Web Components and modern web tools.
Stars: ✭ 30 (-57.75%)
Mutual labels:  webcomponents, lit-html
MoleculeJS
A library for creating fast and reactive Custom Elements
Stars: ✭ 39 (-45.07%)
Mutual labels:  webcomponents, lit-html
effectiveweb.training
Repository for Effective Web Online Course / airhacks.io
Stars: ✭ 17 (-76.06%)
Mutual labels:  lit-html
webcomponents.dev
Web Components IDE
Stars: ✭ 51 (-28.17%)
Mutual labels:  webcomponents
pwa-lit-template
A template for building Progressive Web Applications using Lit and Vaadin Router.
Stars: ✭ 159 (+123.94%)
Mutual labels:  lit-html
web-components
A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
Stars: ✭ 322 (+353.52%)
Mutual labels:  webcomponents
iron-swipeable-pages
[Polymer 1.x] Element that enables switching between different pages by swiping gesture.
Stars: ✭ 51 (-28.17%)
Mutual labels:  webcomponents
Ionicons
Premium hand-crafted icons built by Ionic, for Ionic apps and web apps everywhere 🌎
Stars: ✭ 15,802 (+22156.34%)
Mutual labels:  webcomponents
Model Viewer
Easily display interactive 3D models on the web and in AR!
Stars: ✭ 3,751 (+5183.1%)
Mutual labels:  webcomponents
Creatability Components
Web components for making creative tools more accessible.
Stars: ✭ 248 (+249.3%)
Mutual labels:  webcomponents
polytimer
polytimer.rocks
Stars: ✭ 24 (-66.2%)
Mutual labels:  webcomponents

fuco

npm install size test codecov

Functional Component like React, but for Web Components.

<!DOCTYPE html>
<html lang="en">
  <body>
    <counter-app></counter-app>
    <script type="module">
      import { html, defineElement, useState } from "//unpkg.com/fuco?module";

      function Counter() {
        const [count, setCount] = useState(0);
        return html`
          <div>${count}</div>
          <button @click=${() => setCount(count + 1)}>+</button>
          <button @click=${() => setCount(count - 1)}>-</button>
        `;
      }

      defineElement("counter-app", Counter);
    </script>
  </body>
</html>

Installation

npm install fuco
# or use yarn
yarn add fuco

Hooks

useAttribute

useAttribute returens attribute value, and updates the component when the attribute specified by the first argument is changed.

defineElement("greet-element", () => {
  const name = useAttribute("name");
  const hidden = useAttribute("hidden", value => value != null);
  if (hidden) {
    return html``;
  }
  return html`
    <div>Hello, ${name}</div>
  `;
});

html`
  <greet-element name="World"></greet-element>
`;
// => `<div>Hello, World</div>`

html`
  <greet-element name="WebComponent" hidden></greet-element>
`;
// => ``

useProperty

useProperty returns element's property value, and updates the component when the property values is changed.

defineElement("card-element", () => {
  const card = useProperty("card");
  return html`
    <div>${card.mark} ${card.value}</div>
  `;
});

const heartAce = { mark: "♥", value: 1 };
html`
  <card-element .card=${heartAce}></card-element>
`;

useDispatchEvent

useDispatchEvent offers dispatch function like dispatchEvent to use CustomEvent.

defineElement("send-message", () => {
  const dispatch = useDispatchEvent("some-message", {
    bubbles: true,
    composed: true
  });
  return html`
    <button @click=${() => dispatch("Hi!")}>Send</button>
  `;
});

// You can listen custom event using `@` prefix.
html`
  <send-message @some-message=${e => console.log(e.detail)}></send-message>
`;

useStyle

useStyle can adapt a StyleSheet to the component.

function HelloWorld() {
  useStyle(
    () => css`
      div {
        color: red;
      }
    `
  );
  return html`
    <div>Hello, world</div>
  `;
}

useState

useState returns a pair of state and setter function, and upadates the component by updating state using setter function.

function Counter() {
  const [count, setCount] = useState(0);
  return html`
    <div>${count}</div>
    <button @click=${() => setCount(count + 1)}>PLUS</button>
  `;
}

useReducer

useReducer returns a pair of state and dispatch function.

function Counter() {
  const [count, dispatch] = useReducer((state, action) => state + action, 0);
  return html`
    <div>${count}</div>
    <button @click=${() => dispatch(1)}>PLUS</button>
  `;
}

useRef

useRef returned a ref object like React's, and you can recieve a DOM by setting ref object to attribute.

function Input() {
  const [value, setValue] = useState("");
  const inputRef = useRef(null);
  return html`
    <input :ref=${inputRef} />
    <button @click=${() => setValue(inputRef.current.value)}>push</button>
  `;
}

useContext

createContext offers Context, and usingContext.defineProvider to define provider, and you can consume it using useContext(Context).

const ThemeContext = createContext();

// define a custom element as Provider
ThemeContext.defineProvider("theme-provider");

const App = () => html`
  <theme-provider .value=${"dark"}>
    <theme-comsumer></theme-comsumer>
  </theme-provider>
`;

// consume context
defineElement("theme-consumer", () => {
  const theme = useContext(ThemeContext);
  return html`
    <div>theme is ${theme}</div>
  `;
});

useEffect

useEffect gives you a side effects. it will run after rendering the component.

function Timer() {
  useEffect(() => {
    const id = setInterval(() => console.log("interval"));
    return () => clearInterval(id);
  }, []);
  return html``;
}

useLayoutEffect

useLayoutEffect runs after the DOM has been updated, but before the browser has had a chance to paint those changes

function Box() {
  const ref = useRef(null);
  useLayoutEffect(() => {
    ref.current.style.top = "100px";
  });
  return html`
    <div :ref=${ref}></div>
  `;
}

useMemo

useMemo returns a memorized value. the value will update when deps given as the second argument.

function Plus() {
  const value = useMemo(() => a + b, [a, b]);
  return html`
    ${value}
  `;
}

useCallback

useCallback returns memorized callback as same as useMemo.

function Greet() {
  const greet = useCallback(() => alert("Hello"));
  return html`
    <button @click=${greet}>hello</button>
  `;
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].