Saturday, July 4, 2026

LWC: Reusable Dynamic Tabs

🗂️ Dynamic Tabs – Reusable Salesforce LWC Component

A production-ready Lightning Web Component that delivers fully accessible, highly configurable dynamic tabs with lazy loading, badge counts, SLDS icons, keyboard navigation, and closeable tabs—all built using native Salesforce Lightning Web Components.

📖 Project Overview

Dynamic Tabs is a reusable Lightning Web Component designed for modern Salesforce applications that require rich tabbed navigation while maintaining excellent performance and accessibility.

Unlike traditional tab implementations that render every panel immediately, this component supports lazy loading, meaning tab content is rendered only when a user opens it for the first time. After the initial load, content is simply shown or hidden without unnecessary re-rendering.

The component also includes badge counters, SLDS icons, closeable tabs, multiple layout variants, keyboard accessibility, and a clean public API that makes it easy to integrate into enterprise Salesforce applications.

✨ Features

Feature Description
Lazy LoadingTab content loads only when activated for the first time.
Badge CountsDisplays per-tab counters with automatic 99+ overflow handling.
SLDS IconsSupports any Salesforce Lightning icon beside the tab label.
Closeable TabsOptional close button with custom tabclose event.
Keyboard NavigationSupports Left, Right, Home and End keyboard shortcuts.
AccessibilityARIA-compliant implementation using tablist, tab and tabpanel roles.
Multiple VariantsSupports Default, Scoped and Vertical SLDS tab layouts.
Programmatic APISwitch tabs and update badge counts directly from JavaScript.
Reusable DesignCan be embedded into any Lightning page or custom component.

🏗 Component Architecture

LWC Reusable Dynamic Tabs

📁 Project Structure

force-app/
└── main/
    └── default/
        └── lwc/
            ├── dynamicTabs/
            │   ├── dynamicTabs.html
            │   ├── dynamicTabs.js
            │   ├── dynamicTabs.css
            │   └── dynamicTabs.js-meta.xml
            │
            ├── dynamicTabPanel/
            │   ├── dynamicTabPanel.html
            │   ├── dynamicTabPanel.js
            │   └── dynamicTabPanel.css
            │
            └── dynamicTabsDemo/

⚙️ Public API

Property / Method Purpose
variantChoose default, scoped, or vertical layout.
defaultTabAutomatically activate a tab on initial render.
switchTab()Programmatically activate any tab.
updateBadge()Update badge counts dynamically.
activeTabReturns the currently active tab.

🔄 Component Workflow

Page Loads
     │
     ▼
Render Tab Navigation
     │
     ▼
Activate Default Tab
     │
     ▼
Lazy Load Panel
     │
     ▼
User Switches Tabs
     │
     ▼
Previously Loaded?
     │
 ┌───┴────┐
 │        │
Yes      No
 │        │
 ▼        ▼
Show     Render Once
Content   Then Cache

⌨️ Keyboard Accessibility

  • ← Move to previous tab
  • → Move to next tab
  • Home jumps to the first tab
  • End jumps to the last tab
  • Fully ARIA-compliant tab navigation
  • Screen reader friendly implementation

🎨 Supported Variants

Variant Description
DefaultStandard Salesforce horizontal tabs.
ScopedSLDS scoped tab style.
VerticalVertical navigation for dashboards and setup pages.

🚀 Deployment

sf org login web --alias myOrg

sf project deploy start \
--source-dir force-app \
--target-org myOrg

🎯 Business Use Cases

  • Account & Contact workspaces
  • Customer Service Consoles
  • Sales dashboards
  • Experience Cloud portals
  • Admin configuration pages
  • Record detail workspaces
  • Multi-step business applications
  • Reusable enterprise component libraries

📌 Conclusion

The Dynamic Tabs component provides a powerful, enterprise-ready tab navigation experience for Salesforce applications. With lazy loading, badge counters, SLDS integration, keyboard accessibility, multiple layout variants, and a clean programmatic API, it enables developers to build scalable, high-performance Lightning applications while delivering an excellent user experience.

Thursday, July 2, 2026

LWC: Reusable Horizontal Bar Chart

📊 Reusable Horizontal Bar Chart for Salesforce LWC

A modern, reusable Lightning Web Component that renders responsive horizontal bar charts with smooth animations, adaptive labels, click-to-filter functionality, and zero third-party JavaScript libraries.

📖 Project Overview

horizontalBarChart is a fully reusable Salesforce Lightning Web Component designed for dashboards, Home Pages, App Pages, and Experience Cloud sites.

The component accepts a simple collection of { id, label, value } objects and automatically renders an attractive horizontal bar chart using native HTML, CSS and Lightning Web Components.

Built without Chart.js, D3.js, or any external dependency, the component offers excellent performance, smooth animations, accessibility, responsive layouts, configurable colors, interactive filtering, and App Builder support.

✨ Features

Feature Description
Animated EntryBars animate smoothly from 0% to their calculated width whenever data changes.
Adaptive LabelsAutomatically positions values inside or outside the bar based on available space.
Click-to-FilterClicking a bar selects it and fires a custom barclick event.
Toggle SelectionClick again to remove the active filter.
Clear Filter ButtonDisplays automatically whenever a filter is active.
External SelectionParent components can control selection using the selectedId property.
Automatic ScalingCalculates maximum value automatically or accepts a custom maxValue.
Large Number FormattingFormats values such as 45K, 1.2M, etc.
Custom ColorsSupports reusable color palettes that cycle automatically.
Legend SupportOptional color legend for dashboard visualization.
Responsive LayoutOptimized for desktop, tablet and mobile devices.
AccessibilityKeyboard navigation, ARIA labels and screen-reader support.

🏗 Component Architecture

Reusable Horizontal Bar Chart

📁 Project Structure

horizontalBarChart/
│
├── horizontalBarChart.html
├── horizontalBarChart.js
├── horizontalBarChart.css
├── horizontalBarChart.js-meta.xml
└── README.md

⚙️ Public API

Property Purpose
dataArray of { id, label, value } objects.
selectedIdExternally control selected bar.
maxValueOverride automatic scaling.
showLegendShow or hide legend.
colorsCustom color palette.

📦 Expected Data Structure

[
  {
    id: "A",
    label: "Prospecting",
    value: 120
  },
  {
    id: "B",
    label: "Qualification",
    value: 85
  },
  {
    id: "C",
    label: "Closed Won",
    value: 42
  }
]

🔄 Event Flow

Load Data
    │
    ▼
Calculate Maximum
    │
    ▼
Render Horizontal Bars
    │
    ▼
Animate Width
    │
    ▼
User Clicks Bar
    │
    ▼
Dispatch "barclick"
    │
    ▼
Parent Dashboard Filters

🎨 Styling Features

  • Salesforce Lightning Design System (SLDS) styling.
  • Uses Lightning Design Tokens.
  • Responsive layout.
  • Animated transitions.
  • Adaptive value labels.
  • Optional legend.
  • Empty state illustration.
  • Theme-friendly custom CSS variables.

♿ Accessibility

  • Keyboard accessible.
  • ARIA-compliant buttons.
  • Screen reader labels.
  • role="button" support.
  • aria-pressed state management.
  • Focus indicators.

🚀 Deployment

sf org login web --alias myOrg

sf project deploy start \
--source-dir force-app \
--target-org myOrg

🎯 Ideal Business Use Cases

  • Opportunity Stage Dashboard
  • Lead Source Analytics
  • Case Status Distribution
  • Revenue Comparison
  • Sales Team Performance
  • Service Metrics
  • Executive KPI Dashboards
  • Experience Cloud Analytics
  • Marketing Campaign Performance
  • Custom Salesforce Reports

📌 Conclusion

The Horizontal Bar Chart component provides an elegant, lightweight, and highly reusable solution for visualizing Salesforce data. Built entirely with Lightning Web Components and native web technologies, it offers smooth animations, adaptive labels, interactive filtering, responsive layouts, accessibility support, and App Builder compatibility—making it an excellent choice for modern Salesforce dashboards and analytics applications.

Tuesday, June 30, 2026

LWC: Reusable Donut / Pie Chart Component

🍩 Reusable Donut / Pie Chart Component for Salesforce LWC

A fully reusable SVG-based Lightning Web Component that renders beautiful, interactive Donut and Pie Charts using pure SVG with zero external JavaScript libraries.

📖 Project Overview

The Donut / Pie Chart Component is a reusable Lightning Web Component built entirely with native Salesforce technologies. It renders interactive charts using pure SVG, supports Apex-powered dynamic data as well as static datasets, and provides configurable legends, animated slices, hover tooltips, accessibility support, and responsive layouts.

Unlike third-party charting libraries, this solution requires zero external dependencies, making deployment simple while maintaining excellent performance and Lightning compatibility.

✨ Key Features

Feature Description
Pure SVG RenderingNo Canvas or third-party chart libraries required.
Donut & Pie ModesSwitch between Donut and Pie using a single property.
Animated SlicesHovered slices expand while remaining slices fade.
Interactive TooltipsDisplays label, value, and percentage on hover.
Configurable LegendSupports stacked and side-by-side layouts.
Dynamic Apex DataAutomatically loads data using Apex Wire.
Static Data SupportAccepts custom chart data from parent components.
Responsive LayoutAutomatically adapts to desktop and mobile screens.
AccessibilityKeyboard navigation, ARIA labels and focus support.
Loading & Error StatesBuilt-in loading, empty data and error handling.

🏗 Component Architecture

Donut Chart - LWC Component Architecture

📁 Project Structure

force-app
└── main
    └── default
        ├── classes
        │   └── DonutChartController.cls
        │
        └── lwc
            └── donutChart
                ├── donutChart.html
                ├── donutChart.js
                ├── donutChart.css
                └── donutChart.js-meta.xml

⚙️ Public API Properties

Property Purpose
titleChart title displayed above the component.
chartTypeChoose between donut or pie.
chartDataStatic chart data supplied by parent LWC.
recordIdAutomatically loads Apex data.
colorPaletteCustom array of chart colors.
showLegendDisplay chart legend.
legendPositionStacked or Side-by-Side layout.
showCenterTextDisplay total value inside the donut.
valuePrefix / valueSuffixFormat displayed values.

💻 Usage Example

<c-donut-chart
    title="Revenue by Stage"
    chart-type="donut"
    show-legend
    legend-position="side-by-side"
    show-center-text
    center-label="Total"
    value-prefix="$"
    chart-data={opportunityData}>
</c-donut-chart>

📊 Supported Features

  • Donut Charts
  • Pie Charts
  • Static Data
  • Apex Wire Data
  • Hover Animation
  • Keyboard Navigation
  • ARIA Accessibility
  • Responsive Layout
  • Custom Color Palette
  • Legend Totals
  • Loading State
  • Error State
  • Empty Data State

🎨 Customisation Options

✔ Custom Color Palette

✔ Legend Title

✔ Legend Position

✔ Center Label

✔ Value Prefix

✔ Value Suffix

✔ Label Field Mapping

✔ Value Field Mapping

✔ Donut / Pie Mode

♿ Accessibility

  • Keyboard accessible slices.
  • Tab navigation support.
  • Meaningful ARIA labels.
  • Screen reader friendly.
  • High contrast compatible.
  • Mobile responsive layout.

🚀 Deployment

sf org login web --alias myOrg

sf project deploy start \
--source-dir force-app \
--target-org myOrg

🎯 Business Use Cases

  • Sales Pipeline Distribution
  • Opportunity Stage Analysis
  • Case Status Dashboard
  • Lead Source Analytics
  • Revenue Breakdown
  • Account Segmentation
  • Executive Dashboards
  • Service Performance Reports
  • Custom CRM Analytics

📌 Conclusion

The Reusable Donut / Pie Chart Component provides a lightweight, modern, and highly configurable visualization solution for Salesforce Lightning applications. Built entirely with native SVG, Lightning Web Components, and Apex, it delivers interactive charts without relying on external JavaScript libraries, making it ideal for enterprise Salesforce projects that require performance, accessibility, and easy customization.