Skip to content
ui8kit

component / components

Cta Actions

Cta Actions component

Install

npx ui8kit add cta-actions

Pulls in: action-group, button, compose, form, group, input, kit-box, kit-button, kit-form, kit-input, kit-label, label, utils

Preview

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add cta-actions
components/cta-actions.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions
  form).
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { ActionSet } from "./cta-actions.types";

  export type CtaActionsProps = {
    id: string;
    actions: ActionSet;
    center?: boolean;
  };
</script>

<script lang="ts">
  import Button from "../compose/Button.svelte";
  import Form from "../compose/Form.svelte";
  import Group from "../compose/Group.svelte";
  import Input from "../compose/Input.svelte";
  import Label from "../compose/Label.svelte";
  import ActionGroup from "../components/action-group.svelte";
  import { cn, tpl } from "../utils";

  let { id, actions, center = false }: CtaActionsProps = $props();
</script>

{#if (actions.mode === "form")}
  <Form method="dialog" class={cn("w-full max-w-md", (center ? "mx-auto" : ""))} data-slot="email-form">
    <Label for={tpl("{0}-email", id)} class="sr-only">
      {actions.emailLabel}
    </Label>
    <Group gap="2" align="start" class="w-full flex-wrap">
      <Input type="email" name="email" class="min-w-0 flex-1" id={tpl("{0}-email", id)} data-slot="field" />
      <Button variant="default" size="default" type="submit">
        {actions.cta}
      </Button>
    </Group>
  </Form>
{:else}
  <ActionGroup
    primary={actions.cta}
    primaryHref={actions.href}
    secondary={((actions.mode === "two") ? actions.secondary : undefined)}
    secondaryHref={actions.secondaryHref}
    align={(center ? "center" : "start")}
  />
{/if}
components/cta-actions.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type ActionSet = {
  /** one or two links, or a form */
  mode?: "one" | "two" | "form";
  /** primary action label */
  cta: string;
  /** the address of the primary action; none: a button, not a link */
  href?: string;
  secondary?: string;
  secondaryHref?: string;
  /** label of the form field (the email field, or the prompt line of HeroPrompt) */
  emailLabel?: string;
};

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add cta-actions
components/cta-actions.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions
 * form).
 */
import { type ReactNode } from "react";
import { Button, Form, Group, Input, Label } from "../compose";
import { ActionGroup } from "../components/action-group";
import { cn, tpl } from "../utils";
import type { ActionSet } from "./cta-actions.types";

export type CtaActionsProps = {
  id: string;
  actions: ActionSet;
  center?: boolean;
};

export function CtaActions({ id, actions, center = false }: CtaActionsProps) {
  return (
    <>
      {(actions.mode === "form") ? (
        <Form method="dialog" className={cn("w-full max-w-md", (center ? "mx-auto" : ""))} data-slot="email-form">
          <Label htmlFor={tpl("{0}-email", id)} className="sr-only">
            {actions.emailLabel}
          </Label>
          <Group gap="2" align="start" className="w-full flex-wrap">
            <Input type="email" name="email" className="min-w-0 flex-1" id={tpl("{0}-email", id)} data-slot="field" />
            <Button variant="default" size="default" type="submit">
              {actions.cta}
            </Button>
          </Group>
        </Form>
      ) : (
        <ActionGroup
          primary={actions.cta}
          primaryHref={actions.href}
          secondary={((actions.mode === "two") ? actions.secondary : undefined)}
          secondaryHref={actions.secondaryHref}
          align={(center ? "center" : "start")}
        />
      )}
    </>
  );
}
components/cta-actions.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type ActionSet = {
  /** one or two links, or a form */
  mode?: "one" | "two" | "form";
  /** primary action label */
  cta: string;
  /** the address of the primary action; none: a button, not a link */
  href?: string;
  secondary?: string;
  secondaryHref?: string;
  /** label of the form field (the email field, or the prompt line of HeroPrompt) */
  emailLabel?: string;
};

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add cta-actions
components/cta-actions.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type ActionSet = {
  /** one or two links, or a form */
  mode?: "one" | "two" | "form";
  /** primary action label */
  cta: string;
  /** the address of the primary action; none: a button, not a link */
  href?: string;
  secondary?: string;
  secondaryHref?: string;
  /** label of the form field (the email field, or the prompt line of HeroPrompt) */
  emailLabel?: string;
};
components/cta-actions.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions
  form).
-->
<script lang="ts">
import type { ActionSet } from "./cta-actions.types";

export type CtaActionsProps = {
  id: string;
  actions: ActionSet;
  center?: boolean;
};
</script>

<script setup lang="ts">
import Button from "../compose/Button.vue";
import Form from "../compose/Form.vue";
import Group from "../compose/Group.vue";
import Input from "../compose/Input.vue";
import Label from "../compose/Label.vue";
import ActionGroup from "../components/action-group.vue";
import { cn, tpl } from "../utils";

const { id, actions, center = false } = defineProps<CtaActionsProps>();
</script>

<template>
  <Form
    v-if="(actions.mode === 'form')"
    method="dialog"
    :class="cn('w-full max-w-md', (center ? 'mx-auto' : ''))"
    data-slot="email-form"
  >
    <Label :for="tpl('{0}-email', id)" class="sr-only">
      {{ actions.emailLabel }}
    </Label>
    <Group gap="2" align="start" class="w-full flex-wrap">
      <Input type="email" name="email" class="min-w-0 flex-1" :id="tpl('{0}-email', id)" data-slot="field" />
      <Button variant="default" size="default" type="submit">
        {{ actions.cta }}
      </Button>
    </Group>
  </Form>
  <ActionGroup v-else
    :primary="actions.cta"
    :primaryHref="actions.href"
    :secondary="((actions.mode === 'two') ? actions.secondary : undefined)"
    :secondaryHref="actions.secondaryHref"
    :align="(center ? 'center' : 'start')"
  />
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add cta-actions
components/cta-actions.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions
 * form).
 */
import { For, type JSX } from "solid-js";
import { Button, Form, Group, Input, Label } from "../compose";
import { ActionGroup } from "../components/action-group";
import { cn, tpl } from "../utils";
import type { ActionSet } from "./cta-actions.types";

export type CtaActionsProps = {
  id: string;
  actions: ActionSet;
  center?: boolean;
};

export function CtaActions({ id, actions, center = false }: CtaActionsProps) {
  return (
    <>
      {(actions.mode === "form") ? (
        <Form method="dialog" class={cn("w-full max-w-md", (center ? "mx-auto" : ""))} data-slot="email-form">
          <Label for={tpl("{0}-email", id)} class="sr-only">
            {actions.emailLabel}
          </Label>
          <Group gap="2" align="start" class="w-full flex-wrap">
            <Input type="email" name="email" class="min-w-0 flex-1" id={tpl("{0}-email", id)} data-slot="field" />
            <Button variant="default" size="default" type="submit">
              {actions.cta}
            </Button>
          </Group>
        </Form>
      ) : (
        <ActionGroup
          primary={actions.cta}
          primaryHref={actions.href}
          secondary={((actions.mode === "two") ? actions.secondary : undefined)}
          secondaryHref={actions.secondaryHref}
          align={(center ? "center" : "start")}
        />
      )}
    </>
  );
}
components/cta-actions.types.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.

export type ActionSet = {
  /** one or two links, or a form */
  mode?: "one" | "two" | "form";
  /** primary action label */
  cta: string;
  /** the address of the primary action; none: a button, not a link */
  href?: string;
  secondary?: string;
  secondaryHref?: string;
  /** label of the form field (the email field, or the prompt line of HeroPrompt) */
  emailLabel?: string;
};

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add cta-actions
blocks/cta-actions.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/cta-actions.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/box"
	"github.com/ui8kit/codegen/generated/templ/ui/button"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/form"
	"github.com/ui8kit/codegen/generated/templ/ui/input"
	"github.com/ui8kit/codegen/generated/templ/ui/label"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// CtaActionsProps are the props of CtaActions; the values are the JSON shapes of the TypeScript props.
type CtaActionsProps struct {
	Id any `json:"id"`
	Actions any `json:"actions"`
	Center any `json:"center"`
}

// The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions form).
templ CtaActions(p CtaActionsProps) {
	{{ vId := p.Id }}
	{{ vActions := p.Actions }}
	{{ vCenter := uiutils.Def(p.Center, false) }}
	if uiutils.Eq(uiutils.Get(vActions, "mode"), "form") {
		@compose.Form(compose.FormProps{FormProps: form.FormProps{Method: "dialog", Class: uiutils.S(uiutils.Cnv("w-full max-w-md", uiutils.Cond(uiutils.T(vCenter), "mx-auto", ""))), Attrs: uiutils.Attrs("data-slot", "email-form")}}) {
			@compose.Label(compose.LabelProps{LabelProps: label.LabelProps{For: uiutils.S(uiutils.Tpl("{0}-email", vId)), Class: "sr-only"}}) {
				{ uiutils.Text(uiutils.Get(vActions, "emailLabel")) }
			}
			@compose.Group(compose.GroupProps{Gap: "2", Align: "start", BoxProps: box.BoxProps{Class: "w-full flex-wrap"}}) {
				@compose.Input(compose.InputProps{InputProps: input.InputProps{Type: "email", Name: "email", Class: "min-w-0 flex-1", Attrs: uiutils.Attrs("id", uiutils.Tpl("{0}-email", vId), "data-slot", "field")}})
				@compose.Button(compose.ButtonProps{Variant: "default", Size: "default", ButtonProps: button.ButtonProps{Type: "submit"}}) {
					{ uiutils.Text(uiutils.Get(vActions, "cta")) }
				}
			}
		}
	} else {
		@ActionGroup(ActionGroupProps{Primary: uiutils.Get(vActions, "cta"), PrimaryHref: uiutils.Get(vActions, "href"), Secondary: uiutils.Cond(uiutils.T(uiutils.Eq(uiutils.Get(vActions, "mode"), "two")), uiutils.Get(vActions, "secondary"), nil), SecondaryHref: uiutils.Get(vActions, "secondaryHref"), Align: uiutils.Cond(uiutils.T(vCenter), "center", "start")})
	}
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add cta-actions
blocks/cta-actions.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/cta-actions.json
    The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions form).
    Props (p): id, actions, center. -#}
{%- set v_id = (p.id ?? null) -%}
{%- set v_actions = (p.actions ?? null) -%}
{%- set v_center = (p.center ?? false) -%}
{%- if og_t(og_eq(og_get(v_actions, ['mode']), 'form')) %}
  {%- set c_4 -%}
    {%- set c_1 -%}
      {{ og_text(og_get(v_actions, ['emailLabel'])) }}
    {%- endset -%}
    {{ include('compose/Label.html.twig', {'htmlFor': og_s(og_tpl('{0}-email', [v_id])), 'class': 'sr-only', 'children': c_1}, with_context = false) }}
    {%- set c_3 -%}
      {{ include('compose/Input.html.twig', {'type': 'email', 'name': 'email', 'class': 'min-w-0 flex-1', 'attrs': og_attrs(['id', og_tpl('{0}-email', [v_id]), 'data-slot', 'field'])}, with_context = false) }}
      {%- set c_2 -%}
        {{ og_text(og_get(v_actions, ['cta'])) }}
      {%- endset -%}
      {{ include('compose/Button.html.twig', {'variant': 'default', 'size': 'default', 'type': 'submit', 'children': c_2}, with_context = false) }}
    {%- endset -%}
    {{ include('compose/Group.html.twig', {'gap': '2', 'align': 'start', 'class': 'w-full flex-wrap', 'children': c_3}, with_context = false) }}
  {%- endset -%}
  {{ include('compose/Form.html.twig', {'method': 'dialog', 'class': og_s(og_cnv(['w-full max-w-md', (og_t(v_center) ? 'mx-auto' : '')])), 'attrs': og_attrs(['data-slot', 'email-form']), 'children': c_4}, with_context = false) }}
{%- else %}
  {{ include('blocks/action-group.html.twig', {'p': {'primary': og_get(v_actions, ['cta']), 'primaryHref': og_get(v_actions, ['href']), 'secondary': (og_t(og_eq(og_get(v_actions, ['mode']), 'two')) ? og_get(v_actions, ['secondary']) : null), 'secondaryHref': og_get(v_actions, ['secondaryHref']), 'align': (og_t(v_center) ? 'center' : 'start')}}, with_context = false) }}
{%- endif %}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add cta-actions
blocks/cta-actions.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/cta-actions.json
    The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions form).
    Props (p): id, actions, center. *}
{var $v_id = ($p['id'] ?? null)}
{var $v_actions = ($p['actions'] ?? null)}
{var $v_center = ($p['center'] ?? false)}
{if og_t(og_eq(og_get($v_actions, ['mode']), 'form'))}
  {capture $c_4}
    {capture $c_1}
      {=og_text(og_get($v_actions, ['emailLabel']))}
    {/capture}
    {=og_include('compose/Label.latte', ['htmlFor' => og_s(og_tpl('{0}-email', [$v_id])), 'class' => 'sr-only', 'children' => (string) $c_1])|noescape}
    {capture $c_3}
      {=og_include('compose/Input.latte', ['type' => 'email', 'name' => 'email', 'class' => 'min-w-0 flex-1', 'attrs' => og_attrs(['id', og_tpl('{0}-email', [$v_id]), 'data-slot', 'field'])])|noescape}
      {capture $c_2}
        {=og_text(og_get($v_actions, ['cta']))}
      {/capture}
      {=og_include('compose/Button.latte', ['variant' => 'default', 'size' => 'default', 'type' => 'submit', 'children' => (string) $c_2])|noescape}
    {/capture}
    {=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'start', 'class' => 'w-full flex-wrap', 'children' => (string) $c_3])|noescape}
  {/capture}
  {=og_include('compose/Form.latte', ['method' => 'dialog', 'class' => og_s(og_cnv(['w-full max-w-md', (og_t($v_center) ? 'mx-auto' : '')])), 'attrs' => og_attrs(['data-slot', 'email-form']), 'children' => (string) $c_4])|noescape}
{else}
  {=og_include('blocks/action-group.latte', ['p' => ['primary' => og_get($v_actions, ['cta']), 'primaryHref' => og_get($v_actions, ['href']), 'secondary' => (og_t(og_eq(og_get($v_actions, ['mode']), 'two')) ? og_get($v_actions, ['secondary']) : null), 'secondaryHref' => og_get($v_actions, ['secondaryHref']), 'align' => (og_t($v_center) ? 'center' : 'start')]])|noescape}
{/if}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add cta-actions
blocks/cta-actions.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/cta-actions.json
    The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions form).
    Props (p): id, actions, center. -#}
{%- set v_id = og_def(p['id'], none) -%}
{%- set v_actions = og_def(p['actions'], none) -%}
{%- set v_center = og_def(p['center'], false) -%}
{%- if og_t(og_eq(og_get(v_actions, ['mode']), 'form')) %}
  {%- set c_4 -%}
    {%- set c_1 -%}
      {{ og_text(og_get(v_actions, ['emailLabel'])) }}
    {%- endset -%}
    {{ og_include('compose/label.html.j2', {'p': {'For': og_s(og_tpl('{0}-email', [v_id])), 'Class': 'sr-only'}, 'children': c_1}) }}
    {%- set c_3 -%}
      {{ og_include('compose/input.html.j2', {'p': {'Type': 'email', 'Name': 'email', 'Class': 'min-w-0 flex-1', 'Attrs': og_attrs(['id', og_tpl('{0}-email', [v_id]), 'data-slot', 'field'])}}) }}
      {%- set c_2 -%}
        {{ og_text(og_get(v_actions, ['cta'])) }}
      {%- endset -%}
      {{ og_include('compose/button.html.j2', {'p': {'Variant': 'default', 'Size': 'default', 'Type': 'submit'}, 'children': c_2}) }}
    {%- endset -%}
    {{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'start', 'Class': 'w-full flex-wrap'}, 'children': c_3}) }}
  {%- endset -%}
  {{ og_include('compose/form.html.j2', {'p': {'Method': 'dialog', 'Class': og_s(og_cnv(['w-full max-w-md', ('mx-auto' if og_t(v_center) else '')])), 'Attrs': og_attrs(['data-slot', 'email-form'])}, 'children': c_4}) }}
{%- else %}
  {{ og_include('blocks/action-group.html.j2', {'p': {'primary': og_get(v_actions, ['cta']), 'primaryHref': og_get(v_actions, ['href']), 'secondary': (og_get(v_actions, ['secondary']) if og_t(og_eq(og_get(v_actions, ['mode']), 'two')) else none), 'secondaryHref': og_get(v_actions, ['secondaryHref']), 'align': ('center' if og_t(v_center) else 'start')}}) }}
{%- endif %}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

The actions of a call to action: one or two links (ActionGroup), or an email field with a button (actions form).

Props of CtaActions
PropTypeDefault Description
id (required)string-
actions (required)ActionSet-
center booleanfalse

Used in