検索バーでは、ユーザーがリストビュー要素を検索できます。または、カスタム検索を実現するための視覚的なUIコンポーネントとして使用できます。
以下のコンポーネントが含まれています
検索バー
名前 | タイプ | デフォルト | 説明 |
---|---|---|---|
clearButton | boolean(真偽値) | true(真) | 入力クリアボタンを追加します |
colors | object(オブジェクト) | Tailwind CSS カラークラスを持つオブジェクト | |
colors.inputBgIos | string(文字列) | '' | |
colors.inputBgMaterial | string(文字列) | 'bg-md-light-secondary-container dark:bg-md-dark-secondary-container' | |
colors.placeholderIos | string(文字列) | '' | |
colors.placeholderMaterial | string(文字列) | 'placeholder-md-light-on-surface-variant dark:placeholder-md-dark-on-surface-variant' | |
component | string(文字列) | 'div' | コンポーネントのHTML要素 |
disableButton | boolean(真偽値) | false(偽) | 検索をキャンセルするためのボタンを追加し、初期状態を設定します |
disableButtonText | string(文字列) | 'キャンセル' | キャンセルボタンのテキスト |
inputId | string(文字列) | 入力ID属性 | |
inputStyle | CSSProperties | 追加の入力クラス | |
placeholder | string(文字列) | 文字列 | '検索' | 検索バーのプレースホルダー |
value | any(任意) | 検索バーの値 | |
onBlur | function(e) |
| |
onChange | function(e) |
| |
onClear | function(e) | クリアボタンクリック時に実行されます | |
onDisable | function(e) | 検索バーが無効化されたときに実行されます | |
onFocus | function(e) |
| |
onInput | function(e) |
|
import React, { useState } from 'react';import {Page,Navbar,NavbarBackLink,Searchbar,List,ListItem,} from 'konsta/react';const items = [{ title: 'FC Ajax' },{ title: 'FC Arsenal' },{ title: 'FC Athletic' },{ title: 'FC Barcelona' },{ title: 'FC Bayern München' },{ title: 'FC Bordeaux' },{ title: 'FC Borussia Dortmund' },{ title: 'FC Chelsea' },{ title: 'FC Galatasaray' },{ title: 'FC Juventus' },{ title: 'FC Liverpool' },{ title: 'FC Manchester City' },{ title: 'FC Manchester United' },{ title: 'FC Paris Saint-Germain' },{ title: 'FC Real Madrid' },{ title: 'FC Tottenham Hotspur' },{ title: 'FC Valencia' },{ title: 'FC West Ham United' },];export default function SearchbarPage() {const [searchQuery, setSearchQuery] = useState('');const handleSearch = (e) => {setSearchQuery(e.target.value);};const handleClear = () => {setSearchQuery('');};const handleDisable = () => {console.log('Disable');};const filteredItems = searchQuery? items.filter((item) =>item.title.toLowerCase().includes(searchQuery.toLowerCase())): items;return (<Page><Navbartitle="Searchbar"subnavbar={<SearchbaronInput={handleSearch}value={searchQuery}onClear={handleClear}disableButtondisableButtonText="Cancel"onDisable={handleDisable}/>}/><List strong insetMaterial outlineIos>{filteredItems.length === 0 ? (<ListItem title="Nothing found" className="text-center" />) : (filteredItems.map((item) => (<ListItem key={item.title} title={item.title} />)))}</List></Page>);}