Search By Chips Block
The SearchByChip Component is a fully customizable and accessible search by chips interface built with React and TypeScript. It provides a complete chip-based search experience with modern design patterns, clickable chip sections, and flexible customization options for filtering and searching functionality.
π Installationβ
npm install @nodeblocks/frontend-search-by-chip-block@0.2.0
π Usageβ
import {SearchByChip} from '@nodeblocks/frontend-search-by-chip-block';
- Basic Usage
- Advanced Usage
function SimpleSearchByChip() { const chips = [ {value: 'web', label: 'Web Development'}, {value: 'mobile', label: 'Mobile Apps'}, {value: 'cloud', label: 'Cloud Services'}, {value: 'analytics', label: 'Data Analytics'}, {value: 'ai', label: 'AI & Machine Learning'}, ]; const handleChipClick = (value) => { console.log('Chip clicked:', value); }; return ( <SearchByChip searchByChipTitle="Find Services" sectionTitle="Popular Categories" subtitle="Browse by category to find what you need" onClickChip={handleChipClick} chips={chips} > <SearchByChip.Title /> <SearchByChip.Subtitle /> <SearchByChip.ChipSection /> </SearchByChip> ); }
import {useState} from 'react'; function AdvancedSearchByChip() { const [selectedChip, setSelectedChip] = useState(null); const chips = [ {value: 'trending', label: 'π₯ Trending'}, {value: 'top-rated', label: 'β Top Rated'}, {value: 'new', label: 'π New'}, {value: 'business', label: 'πΌ Business'}, {value: 'creative', label: 'π¨ Creative'}, {value: 'analytics', label: 'π Analytics'}, {value: 'security', label: 'π Security'}, {value: 'startup', label: 'π Startup'}, ]; const handleChipClick = (value) => { setSelectedChip(value); console.log('Selected:', value); }; return ( <SearchByChip searchByChipTitle="Discover Solutions" sectionTitle="Browse Categories" subtitle="Search through thousands of verified services and tools" onClickChip={handleChipClick} chips={chips} sx={{ background: 'linear-gradient(180deg, #1e1b4b 0%, #312e81 100%)', py: 10, px: 4, minHeight: 400, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', }} > {({defaultBlocks, defaultBlockOrder}) => { const customHeader = ( <div style={{textAlign: 'center', marginBottom: '32px'}}> <div style={{ display: 'inline-flex', alignItems: 'center', gap: '8px', background: 'rgba(255,255,255,0.1)', padding: '8px 16px', borderRadius: '20px', marginBottom: '16px', }} > <div style={{ width: '8px', height: '8px', borderRadius: '50%', background: '#34d399', }} /> <span style={{ color: '#a5b4fc', fontSize: '13px', fontWeight: '500', }} > 10,000+ solutions available </span> </div> <h1 style={{ color: '#ffffff', fontSize: '48px', fontWeight: '800', margin: '0 0 12px 0', lineHeight: 1.1, }} > Find Your Perfect <br /> <span style={{ background: 'linear-gradient(135deg, #818cf8 0%, #c4b5fd 100%)', backgroundClip: 'text', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', }} > Business Solution </span> </h1> <p style={{ color: '#a5b4fc', fontSize: '18px', margin: 0, maxWidth: '500px', }} > Search through thousands of verified services and tools </p> </div> ); const customChipSection = ( <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '16px', }} > {selectedChip && ( <div style={{ padding: '8px 16px', background: 'rgba(129,140,248,0.2)', borderRadius: '8px', color: '#c4b5fd', fontSize: '14px', marginBottom: '8px', }} > Selected: {selectedChip} </div> )} <div style={{ display: 'flex', flexWrap: 'wrap', gap: '10px', justifyContent: 'center', maxWidth: '700px', }} > <span style={{ color: '#94a3b8', fontSize: '14px', marginRight: '8px', alignSelf: 'center', }} > Popular: </span> {chips.map((chip, index) => ( <button key={index} onClick={() => handleChipClick(chip.value)} style={{ padding: '10px 18px', borderRadius: '12px', background: selectedChip === chip.value ? 'rgba(129,140,248,0.4)' : 'rgba(255,255,255,0.08)', color: '#e0e7ff', border: '1px solid rgba(255,255,255,0.1)', fontSize: '14px', fontWeight: '500', cursor: 'pointer', transition: 'all 0.2s ease', }} > {chip.label} </button> ))} </div> </div> ); return { blocks: { ...defaultBlocks, title: customHeader, subtitle: <></>, chipSection: customChipSection, }, blockOrder: defaultBlockOrder, }; }} </SearchByChip> ); }
π§ Props Referenceβ
Main Component Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
searchByChipTitle | ReactNode | Required | Main title for the search by chip section |
sectionTitle | ReactNode | Required | Title for the chip section |
subtitle | ReactNode | Required | Subtitle text displayed below the main title |
onClickChip | (value: string) => void | Required | Callback function triggered when a chip is clicked |
chips | Chip[] | Required | Array of chip objects to display |
className | string | undefined | Additional CSS class name for styling the container |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
children | BlocksOverride | undefined | Function to override default blocks or add custom chip components |
Default sx:
{
p: 2,
gap: 0.5,
bgcolor: 'background.paper',
textAlign: 'center',
containerType: 'inline-size'
}
Note: The main component inherits all MUI Stack props.
Sub-Componentsβ
The SearchByChip component provides several sub-components. All sub-components receive their default values from the main component's context and can override these values through props.
SearchByChip.Titleβ
Renders the main title for the search section.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | searchByChipTitle from context | Custom content to override default title rendering |
searchByChipTitle | ReactNode | From context | Title text (overrides context) |
variant | string | 'h4' | Typography variant |
component | ElementType | 'h1' | The component used for the root node |
sx | SxProps<Theme> | undefined | MUI System prop for custom styling |
Note: This component inherits all MUI Typography props.
SearchByChip.Subtitleβ
Renders the subtitle below the main title.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | subtitle from context | Custom content to override default subtitle rendering |
subtitle | ReactNode | From context | Subtitle text (overrides context) |
variant | string | 'h6' | Typography variant |
component | ElementType | 'h6' | The component used for the root node |
sx | SxProps<Theme> | { color: 'primary.main' } | MUI System prop for custom styling |
Note: This component inherits all MUI Typography props.
SearchByChip.SectionTitleβ
Renders the title for the chip section.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | sectionTitle from context | Custom content to override default section title rendering |
sectionTitle | ReactNode | From context | Section title text (overrides context) |
variant | string | 'body1' | Typography variant |
component | ElementType | 'h6' | The component used for the root node |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
Default sx:
{
px: 2,
py: 1.875,
fontWeight: theme.typography.h6.fontWeight
}
Note: This component inherits all MUI Typography props.
SearchByChip.ChipItemβ
Renders an individual clickable chip button.
| Prop | Type | Default | Description |
|---|---|---|---|
onClickChip | (value: string) => void | Required | Callback function for chip click events |
value | string | Required | Unique value identifier for the chip |
label | ReactNode | Required | Display text for the chip |
startIcon | ReactNode | <SearchByChip.ChipIcon /> | Icon displayed at the start of the chip |
variant | 'text' | 'outlined' | 'contained' | 'outlined' | Button variant |
size | 'small' | 'medium' | 'large' | 'small' | Button size |
sx | SxProps<Theme> | See below | MUI System prop for custom styling |
Default sx:
{
'&&': {
fontWeight: theme.typography.fontWeightLight,
py: '7px',
px: 2,
borderColor: 'grey.50',
bgcolor: 'background.paper'
},
'&:hover': {
boxShadow: '0 2px 6px rgba(0, 0, 0, 0.1)'
}
}
Note: This component inherits all MUI Button props (except children).
SearchByChip.ChipIconβ
Renders the default checkmark icon for chips.
| Prop | Type | Default | Description |
|---|---|---|---|
sx | SxProps<Theme> | { width: 16, height: 16, color: 'primary.main' } | MUI System prop for custom styling |
Note: This component uses MUI SvgIcon and renders a checkmark icon. It accepts no props but uses default styling.
SearchByChip.ChipSectionβ
Renders the container for chips including section title and chip items.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Default chip rendering | Custom content to override default chip section rendering |
chips | Chip[] | From context | Array of chip objects to display (overrides context) |
sectionTitle | ReactNode | From context | Title for the chip section (overrides context) |
onClickChip | (value: string) => void | From context | Callback for chip clicks (overrides context) |
sx | SxProps<Theme> | undefined | MUI System prop for custom styling |
Note: This component inherits all MUI Stack props. Internally renders SearchByChip.SectionTitle and a flex container with SearchByChip.ChipItem elements.
π¨ Configuration examplesβ
Custom Title Stylingβ
<SearchByChip.Title
variant="h3"
sx={{ color: 'primary.main', fontWeight: 700 }}
/>
Custom Chip Item Stylingβ
<SearchByChip.ChipItem
value="custom"
label="Custom Chip"
onClickChip={(value) => console.log(value)}
variant="contained"
sx={{ borderRadius: 4, px: 3 }}
/>
Custom Chip Sectionβ
<SearchByChip.ChipSection
sx={{
bgcolor: 'grey.50',
borderRadius: 2,
p: 2,
}}
/>
Custom Stylingβ
function CustomStyledSearchByChip() {
const chips = [
{value: 'frontend', label: 'Frontend'},
{value: 'backend', label: 'Backend'},
{value: 'devops', label: 'DevOps'},
{value: 'design', label: 'Design'},
];
return (
<SearchByChip
searchByChipTitle="Search Categories"
sectionTitle="Select a Category"
subtitle="Choose from popular categories below"
onClickChip={value => console.log('Clicked:', value)}
chips={chips}
sx={{
bgcolor: 'grey.50',
p: 4,
borderRadius: 3,
}}
>
<SearchByChip.Title
sx={{
color: 'primary.dark',
fontWeight: 700,
fontSize: 28,
}}
/>
<SearchByChip.Subtitle
sx={{
color: 'text.secondary',
mb: 2,
}}
/>
<SearchByChip.ChipSection
sx={{
'& .MuiButton-root': {
bgcolor: 'primary.main',
color: 'white',
borderRadius: 2,
'&:hover': {
bgcolor: 'primary.dark',
},
},
}}
/>
</SearchByChip>
);
}
Chips with Iconsβ
function SearchByChipWithIcons() {
const chips = [
{value: 'web', label: 'Web', icon: <span>π</span>},
{value: 'mobile', label: 'Mobile', icon: <span>π±</span>},
{value: 'desktop', label: 'Desktop', icon: <span>π₯οΈ</span>},
{value: 'cloud', label: 'Cloud', icon: <span>βοΈ</span>},
];
return (
<SearchByChip
searchByChipTitle="Platform Selection"
sectionTitle="Choose Your Platform"
subtitle="Select the platform you want to develop for"
onClickChip={value => console.log('Platform:', value)}
chips={chips}
sx={{
p: 4,
bgcolor: '#f8fafc',
borderRadius: 2,
}}
>
<SearchByChip.Title />
<SearchByChip.Subtitle />
<SearchByChip.ChipSection />
</SearchByChip>
);
}
π§ TypeScript Supportβ
Full TypeScript support with comprehensive type definitions:
import {SearchByChip} from '@nodeblocks/frontend-search-by-chip-block';
import React from 'react';
interface ChipData {
value: string;
label: string;
icon?: React.ReactNode;
}
function TypedSearchByChip() {
const searchChips: ChipData[] = [
{value: 'react', label: 'React'},
{value: 'typescript', label: 'TypeScript'},
{value: 'nodejs', label: 'Node.js'},
{value: 'graphql', label: 'GraphQL'},
{value: 'aws', label: 'AWS'},
];
const handleChipClick = (value: string): void => {
console.log('Selected technology:', value);
// Navigate or filter logic
};
return (
<SearchByChip
searchByChipTitle="Search Technologies"
sectionTitle="Popular Technologies"
subtitle="Click on a chip to filter by technology"
onClickChip={handleChipClick}
chips={searchChips}
spacing={3}
sx={{
maxWidth: 800,
mx: 'auto',
p: 4,
}}
>
<SearchByChip.Title />
<SearchByChip.Subtitle />
<SearchByChip.SectionTitle />
<SearchByChip.ChipSection />
</SearchByChip>
);
}
π Notesβ
- The main component uses MUI
Stackwith default padding, gap, and centered text alignment. - All typography components (
Title,Subtitle,SectionTitle) inherit MUITypographyprops. ChipItemuses MUIButtonwithvariant="outlined"andsize="small"by default.- Each chip can have a custom
iconproperty that overrides the defaultstartIcon. - The default
ChipIconis a checkmark SVG rendered via MUISvgIcon. - The
ChipSectionuses container queries (containerType: 'inline-size') for responsive chip layout. - Context values (
searchByChipTitle,subtitle,sectionTitle,chips,onClickChip) are shared via React Context and can be overridden at the sub-component level.
Built with β€οΈ using React, TypeScript, and MUI.