-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add a new doc for Dropdown to describe how to associate i…
…t with label
- Loading branch information
Showing
2 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { DocSectionCode } from '@/components/doc/common/docsectioncode'; | ||
import { DocSectionText } from '@/components/doc/common/docsectiontext'; | ||
import { Dropdown } from '@/components/lib/dropdown/Dropdown'; | ||
import { useState } from 'react'; | ||
|
||
export function LabelDoc(props) { | ||
const [selectedCity, setSelectedCity] = useState(null); | ||
const cities = [ | ||
{ name: 'New York', code: 'NY' }, | ||
{ name: 'Rome', code: 'RM' }, | ||
{ name: 'London', code: 'LDN' }, | ||
{ name: 'Istanbul', code: 'IST' }, | ||
{ name: 'Paris', code: 'PRS' } | ||
]; | ||
|
||
const code = { | ||
basic: ` | ||
<div> | ||
<label htmlFor="dd-city" id="dd-city-label">Select a City</label> | ||
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" /> | ||
</div> | ||
`, | ||
javascript: ` | ||
import React, { useState } from "react"; | ||
import { Dropdown } from 'primereact/dropdown'; | ||
export default function FloatLabelDemo() { | ||
const [selectedCity, setSelectedCity] = useState(null); | ||
const cities = [ | ||
{ name: 'New York', code: 'NY' }, | ||
{ name: 'Rome', code: 'RM' }, | ||
{ name: 'London', code: 'LDN' }, | ||
{ name: 'Istanbul', code: 'IST' }, | ||
{ name: 'Paris', code: 'PRS' } | ||
]; | ||
return ( | ||
<div className="card flex justify-content-center"> | ||
<div className="w-full md:w-14rem"> | ||
<label htmlFor="dd-city" id="dd-city-label">Select a City</label> | ||
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
`, | ||
typescript: ` | ||
import React, { useState } from "react"; | ||
import { Dropdown, DropdownChangeEvent } from 'primereact/dropdown'; | ||
import { div } from 'primereact/floatlabel'; | ||
interface City { | ||
name: string; | ||
code: string; | ||
} | ||
export default function FloatLabelDemo() { | ||
const [selectedCity, setSelectedCity] = useState<City | null>(null); | ||
const cities: City[] = [ | ||
{ name: 'New York', code: 'NY' }, | ||
{ name: 'Rome', code: 'RM' }, | ||
{ name: 'London', code: 'LDN' }, | ||
{ name: 'Istanbul', code: 'IST' }, | ||
{ name: 'Paris', code: 'PRS' } | ||
]; | ||
return ( | ||
<div className="card flex justify-content-center"> | ||
<div className="w-full md:w-14rem"> | ||
<label htmlFor="dd-city" id="dd-city-label">Select a City</label> | ||
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e: DropdownChangeEvent) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
` | ||
}; | ||
|
||
return ( | ||
<> | ||
<DocSectionText {...props}> | ||
<p> | ||
Dropdown associated with a label using the <i>aria-labelledby</i> property and the label element's <i>id</i> attribute. | ||
</p> | ||
</DocSectionText> | ||
<div className="card flex justify-content-center"> | ||
<div className="w-full md:w-14rem"> | ||
<label className="px-2" htmlFor="dd-city" id="dd-city-label"> | ||
Select a City | ||
</label> | ||
<Dropdown ariaLabelledBy="dd-city-label" inputId="dd-city" value={selectedCity} onChange={(e) => setSelectedCity(e.value)} options={cities} optionLabel="name" className="w-full" /> | ||
</div> | ||
</div> | ||
<DocSectionCode code={code} /> | ||
</> | ||
); | ||
} |