-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate badge components and wrappers, general cleanup
- Loading branch information
1 parent
a8aaad9
commit af8eac5
Showing
42 changed files
with
517 additions
and
348 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
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
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgeImage/BadgeImage.stories.tsx
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 @@ | ||
// TODO |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgeImage/BadgeImage.test.tsx
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 @@ | ||
// TODO |
61 changes: 61 additions & 0 deletions
61
packages/snap-preact-components/src/components/Atoms/BadgeImage/BadgeImage.tsx
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,61 @@ | ||
/** @jsx jsx */ | ||
import { Fragment, h } from 'preact'; | ||
|
||
import { jsx, css } from '@emotion/react'; | ||
import classnames from 'classnames'; | ||
import { observer } from 'mobx-react-lite'; | ||
|
||
import { Theme, useTheme, CacheProvider } from '../../../providers'; | ||
import { ComponentProps, StylingCSS } from '../../../types'; | ||
import type { ResultBadge, OverlayResultBadge } from '@searchspring/snap-store-mobx'; | ||
|
||
const CSS = { | ||
BadgeImage: ({}: BadgeImageProps) => { | ||
return css({}); | ||
}, | ||
}; | ||
|
||
export const BadgeImage = observer((properties: BadgeImageProps): JSX.Element => { | ||
const globalTheme: Theme = useTheme(); | ||
|
||
const props: BadgeImageProps = { | ||
// default props | ||
// global theme | ||
...globalTheme?.components?.badgeImage, | ||
// props | ||
...properties, | ||
...properties.theme?.components?.badgeImage, | ||
}; | ||
const { badge, disableStyles, className, style } = props; | ||
|
||
const styling: { css?: StylingCSS } = {}; | ||
|
||
if (!disableStyles) { | ||
styling.css = [CSS.BadgeImage(props), style]; | ||
} else if (style) { | ||
styling.css = [style]; | ||
} | ||
|
||
return badge?.parameters?.url ? ( | ||
<CacheProvider> | ||
<img | ||
{...styling} | ||
className={classnames( | ||
'ss__badge-image', | ||
`ss__badge-image--${badge.component}`, | ||
`ss__badge-image--${badge.location}`, | ||
`ss__badge-image--${badge.tag}`, | ||
className | ||
)} | ||
alt={badge.label} | ||
src={badge.parameters.url} | ||
/> | ||
</CacheProvider> | ||
) : ( | ||
<Fragment /> | ||
); | ||
}); | ||
|
||
export interface BadgeImageProps extends ComponentProps { | ||
badge: ResultBadge | OverlayResultBadge; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgeImage/index.ts
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 @@ | ||
export * from './BadgeImage'; |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgeImage/readme.md
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 @@ | ||
# BadgeImage // TODO |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgePill/BadgePill.stories.tsx
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 @@ | ||
// TODO |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgePill/BadgePill.test.tsx
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 @@ | ||
// TODO |
68 changes: 68 additions & 0 deletions
68
packages/snap-preact-components/src/components/Atoms/BadgePill/BadgePill.tsx
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,68 @@ | ||
/** @jsx jsx */ | ||
import { Fragment, h } from 'preact'; | ||
|
||
import { jsx, css } from '@emotion/react'; | ||
import classnames from 'classnames'; | ||
import { observer } from 'mobx-react-lite'; | ||
|
||
import { Theme, useTheme, CacheProvider } from '../../../providers'; | ||
import { ComponentProps, StylingCSS } from '../../../types'; | ||
import type { ResultBadge, OverlayResultBadge } from '@searchspring/snap-store-mobx'; | ||
|
||
const CSS = { | ||
BadgePill: (props: BadgePillProps) => { | ||
const { parameters } = props.badge; | ||
const { color, colorText } = parameters; | ||
return css({ | ||
padding: '0.2em 0.5em', | ||
|
||
background: color || 'rgba(255, 255, 255, 0.5)', | ||
color: colorText || '#000000', | ||
}); | ||
}, | ||
}; | ||
|
||
export const BadgePill = observer((properties: BadgePillProps): JSX.Element => { | ||
const globalTheme: Theme = useTheme(); | ||
|
||
const props: BadgePillProps = { | ||
// default props | ||
// global theme | ||
...globalTheme?.components?.badgePill, | ||
// props | ||
...properties, | ||
...properties.theme?.components?.badgePill, | ||
}; | ||
const { badge, disableStyles, className, style } = props; | ||
|
||
const styling: { css?: StylingCSS } = {}; | ||
|
||
if (!disableStyles) { | ||
styling.css = [CSS.BadgePill(props), style]; | ||
} else if (style) { | ||
styling.css = [style]; | ||
} | ||
|
||
return badge ? ( | ||
<CacheProvider> | ||
<div | ||
{...styling} | ||
className={classnames( | ||
'ss__badge-pill', | ||
`ss__badge-pill--${badge.component}`, | ||
`ss__badge-pill--${badge.location}`, | ||
`ss__badge-pill--${badge.tag}`, | ||
className | ||
)} | ||
> | ||
{badge.label} | ||
</div> | ||
</CacheProvider> | ||
) : ( | ||
<Fragment /> | ||
); | ||
}); | ||
|
||
export interface BadgePillProps extends ComponentProps { | ||
badge: ResultBadge | OverlayResultBadge; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/snap-preact-components/src/components/Atoms/BadgePill/index.ts
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 @@ | ||
export * from './BadgePill'; |
2 changes: 2 additions & 0 deletions
2
packages/snap-preact-components/src/components/Atoms/BadgePill/readme.md
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,2 @@ | ||
# BadgePill // TODO | ||
|
Empty file.
5 changes: 0 additions & 5 deletions
5
packages/snap-preact-components/src/components/Atoms/SelfServeBadge/SelfServeBadge.test.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.