forked from algolia/instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ts): migrate geo components (algolia#4800)
* refactor(ts): migrate geo components * update snapshots
- Loading branch information
Showing
11 changed files
with
194 additions
and
171 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
/** @jsx h */ | ||
|
||
import { h, ComponentChildren } from 'preact'; | ||
|
||
type Props = { | ||
className: string; | ||
onClick(event: MouseEvent): void; | ||
children: ComponentChildren; | ||
disabled?: boolean; | ||
}; | ||
|
||
const GeoSearchButton = ({ | ||
className, | ||
disabled = false, | ||
onClick, | ||
children, | ||
}: Props) => ( | ||
<button className={className} onClick={onClick} disabled={disabled}> | ||
{children} | ||
</button> | ||
); | ||
|
||
export default GeoSearchButton; |
This file was deleted.
Oops, something went wrong.
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,110 @@ | ||
/** @jsx h */ | ||
|
||
import { h, Fragment } from 'preact'; | ||
import cx from 'classnames'; | ||
import Template from '../Template/Template'; | ||
import GeoSearchButton from './GeoSearchButton'; | ||
import GeoSearchToggle from './GeoSearchToggle'; | ||
import { | ||
GeoSearchCSSClasses, | ||
GeoSearchTemplates, | ||
} from '../../widgets/geo-search/geo-search'; | ||
import { ComponentCSSClasses } from '../../types'; | ||
import { PreparedTemplateProps } from '../../lib/utils/prepareTemplateProps'; | ||
|
||
type Props = { | ||
cssClasses: ComponentCSSClasses<GeoSearchCSSClasses>; | ||
enableRefine: boolean; | ||
enableRefineControl: boolean; | ||
enableClearMapRefinement: boolean; | ||
isRefineOnMapMove: boolean; | ||
isRefinedWithMap: boolean; | ||
hasMapMoveSinceLastRefine: boolean; | ||
onRefineToggle(event: Event): void; | ||
onRefineClick(event: MouseEvent): void; | ||
onClearClick(event: MouseEvent): void; | ||
templateProps: PreparedTemplateProps<GeoSearchTemplates>; | ||
}; | ||
|
||
const GeoSearchControls = ({ | ||
cssClasses, | ||
enableRefine, | ||
enableRefineControl, | ||
enableClearMapRefinement, | ||
isRefineOnMapMove, | ||
isRefinedWithMap, | ||
hasMapMoveSinceLastRefine, | ||
onRefineToggle, | ||
onRefineClick, | ||
onClearClick, | ||
templateProps, | ||
}: Props) => ( | ||
<Fragment> | ||
{enableRefine && ( | ||
<div> | ||
{enableRefineControl && ( | ||
<div className={cssClasses.control}> | ||
{isRefineOnMapMove || !hasMapMoveSinceLastRefine ? ( | ||
<GeoSearchToggle | ||
classNameLabel={cx(cssClasses.label, { | ||
[cssClasses.selectedLabel]: isRefineOnMapMove, | ||
})} | ||
classNameInput={cssClasses.input} | ||
checked={isRefineOnMapMove} | ||
onToggle={onRefineToggle} | ||
> | ||
<Template | ||
{...templateProps} | ||
templateKey="toggle" | ||
rootTagName="span" | ||
/> | ||
</GeoSearchToggle> | ||
) : ( | ||
<GeoSearchButton | ||
className={cssClasses.redo} | ||
disabled={!hasMapMoveSinceLastRefine} | ||
onClick={onRefineClick} | ||
> | ||
<Template | ||
{...templateProps} | ||
templateKey="redo" | ||
rootTagName="span" | ||
/> | ||
</GeoSearchButton> | ||
)} | ||
</div> | ||
)} | ||
|
||
{!enableRefineControl && !isRefineOnMapMove && ( | ||
<div className={cssClasses.control}> | ||
<GeoSearchButton | ||
className={cx(cssClasses.redo, { | ||
[cssClasses.disabledRedo]: !hasMapMoveSinceLastRefine, | ||
})} | ||
disabled={!hasMapMoveSinceLastRefine} | ||
onClick={onRefineClick} | ||
> | ||
<Template | ||
{...templateProps} | ||
templateKey="redo" | ||
rootTagName="span" | ||
/> | ||
</GeoSearchButton> | ||
</div> | ||
)} | ||
|
||
{enableClearMapRefinement && isRefinedWithMap && ( | ||
<GeoSearchButton className={cssClasses.reset} onClick={onClearClick}> | ||
<Template | ||
{...templateProps} | ||
templateKey="reset" | ||
rootTagName="span" | ||
/> | ||
</GeoSearchButton> | ||
)} | ||
</div> | ||
)} | ||
</Fragment> | ||
); | ||
|
||
export default GeoSearchControls; |
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
Oops, something went wrong.