4.4.13 • Published 5 months ago

@conectate/ct-list v4.4.13

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 months ago

@conectate/ct-list

A versatile list item component for creating navigation menus, action lists, and interactive elements with icon support and flexible styling options.

Table of Contents

Installation

Install via npm, yarn, or pnpm:

# npm
npm i @conectate/ct-list

# yarn
yarn add @conectate/ct-list

# pnpm
pnpm i @conectate/ct-list

Features

  • Flexible Layout: Slots for prefix, main content, and suffix elements
  • Icon Support: Built-in support for Material Icons via ct-icon
  • Link Capability: Can function as navigation links
  • Interactive: Hover states and click handling
  • Menu Integration: Automatically closes parent menus when clicked
  • Customizable: Multiple styling options via CSS variables
  • Accessible: Built with proper semantics and keyboard navigation support

Basic Usage

Import the component and use it in your HTML:

// Import the component
import '@conectate/ct-list/ct-list-item.js';
<!-- Simple list item with text -->
<ct-list-item text="Settings"></ct-list-item>

<!-- With icon -->
<ct-list-item icon="settings" text="Settings"></ct-list-item>

<!-- As a navigation link -->
<ct-list-item icon="home" text="Home" href="/home"></ct-list-item>

<!-- Using custom SVG icon -->
<ct-list-item svg="<svg viewBox='0 0 24 24'><path d='M12 2L2 7l10 5 10-5-10-5z'/></svg>" text="Custom Icon"> </ct-list-item>

Advanced Usage

Custom Content with Slots

<ct-list-item>
	<span slot="prefix">🔔</span>
	Notifications
	<span slot="suffix" class="badge">5</span>
</ct-list-item>

Keep Menu Open

<ct-button-menu>
	<ct-list-item text="Option 1"></ct-list-item>
	<ct-list-item text="Option with submenu" keep-open></ct-list-item>
	<ct-list-item text="Option 3"></ct-list-item>
</ct-button-menu>

Open Links in New Tab

<ct-list-item text="External Link" icon="open_in_new" href="https://example.com" target="_blank"> </ct-list-item>

API Reference

Properties

PropertyTypeDefaultDescription
textstring""Text content to display in the item
iconstringundefinedMaterial Icon name to display
svgstring""Custom SVG content for the icon
hrefstringundefinedURL the item navigates to when clicked
linkstringundefinedDeprecated, use href instead
targetstringundefinedLink target ("_self", "_top", "_blank")
keepOpenbooleanfalseWhen true, parent menus won't close on click
hideoutlinebooleanfalseHides the bottom border

Slots

SlotDescription
defaultMain content area, used with or instead of the text property
prefixContent shown before the main text (left side in LTR layouts)
suffixContent shown after the main text (right side in LTR layouts)

CSS Custom Properties

PropertyDescriptionDefault
--ct-list-item--white-spaceControls text wrappingnowrap
--ct-icon-sizeSize of the icon21px
--color-outlineColor of the bottom bordertransparent
--color-primaryColor used for outline when focusedinherited

Methods

MethodDescriptionParameters
closeMenu()Closes parent menu elementsevent: MouseEvent

Common Patterns

Navigation Menu

<nav>
	<ct-list-item icon="home" text="Home" href="/"></ct-list-item>
	<ct-list-item icon="person" text="Profile" href="/profile"></ct-list-item>
	<ct-list-item icon="settings" text="Settings" href="/settings"></ct-list-item>
	<ct-list-item icon="help" text="Help" href="/help"></ct-list-item>
</nav>

Settings List

<div class="settings-group">
	<h3>Account Settings</h3>
	<ct-list-item icon="account_circle" text="Profile Information"></ct-list-item>
	<ct-list-item icon="lock" text="Password & Security"></ct-list-item>
	<ct-list-item icon="notifications" text="Notification Preferences"></ct-list-item>
</div>

Action Items

<div class="actions">
	<ct-list-item icon="save" text="Save Changes" @click="${this.saveChanges}"></ct-list-item>
	<ct-list-item icon="delete" text="Delete Item" @click="${this.deleteItem}"></ct-list-item>
	<ct-list-item icon="share" text="Share" @click="${this.share}"></ct-list-item>
</div>

Integration

With ct-button-menu

Create dropdown menus with list items:

<ct-button-menu>
	<button slot="trigger">Menu</button>
	<ct-list-item icon="content_cut" text="Cut"></ct-list-item>
	<ct-list-item icon="content_copy" text="Copy"></ct-list-item>
	<ct-list-item icon="content_paste" text="Paste"></ct-list-item>
</ct-button-menu>

With Routers

Works with popular routing libraries:

import { LitElement, html } from 'lit';
import '@conectate/ct-list/ct-list-item.js';
import { router } from 'your-router-library';

class AppNavigation extends LitElement {
  render() {
    return html`
      <nav>
        ${router.routes.map(route => html`
          <ct-list-item
            icon=${route.icon}
            text=${route.name}
            href=${route.path}
            ?selected=${router.currentPath === route.path}>
          </ct-list-item>
        `)}
      </nav>
    `;
  }
}

Styling Examples

Basic Styling

ct-list-item {
	--ct-icon-size: 24px;
	--color-outline: #e0e0e0;
}

Material Design Style

ct-list-item {
	--ct-list-item--white-space: normal;
	--color-primary: #6200ee;
	border-radius: 4px;
	margin: 4px 0;
}

ct-list-item:hover {
	background-color: rgba(98, 0, 238, 0.08);
}

Navigation Style

ct-list-item {
	--ct-icon-size: 24px;
	height: 48px;
	border-radius: 0 24px 24px 0;
	margin-right: 8px;
}

ct-list-item[selected] {
	background-color: rgba(98, 0, 238, 0.12);
	color: #6200ee;
	font-weight: 500;
}

Follow Me

Herberth Obregón

https://x.com/herberthobregon

https://dev.to/herberthobregon

Contributing

  1. Fork the repo
  2. Create a new branch: git checkout -b feature-branch
  3. Commit your changes: git commit -m 'Add new feature'
  4. Push to your branch: git push origin feature-branch
  5. Open a pull request!

License

See LICENSE

4.4.9

6 months ago

4.4.10

6 months ago

4.4.1

8 months ago

4.4.0

8 months ago

4.3.1

9 months ago

4.4.2

8 months ago

4.4.13

5 months ago

4.4.12

6 months ago

4.3.0

9 months ago

4.4.11

6 months ago

4.0.0

1 year ago

3.9.3

2 years ago

3.12.4

2 years ago

3.9.0

2 years ago

3.8.1

2 years ago

3.12.7

2 years ago

3.9.4

2 years ago

3.11.0

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.12.1

2 years ago

3.12.0

2 years ago

3.11.1

2 years ago

3.7.5

3 years ago

3.7.4

3 years ago

3.7.3

3 years ago

3.7.2

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.6.0

4 years ago

3.6.3

4 years ago

3.5.11

4 years ago

3.5.5

4 years ago

3.5.0

4 years ago

3.4.0

4 years ago

3.3.1

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago