-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
452 additions
and
282 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
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
70 changes: 70 additions & 0 deletions
70
packages/components/src/functional-components/Alert/Alert.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,70 @@ | ||
import { h, type FunctionalComponent as FC } from '@stencil/core'; | ||
import type { JSXBase } from '@stencil/core/internal'; | ||
import clsx from 'clsx'; | ||
import type { InternalAlertProps } from '../../schema'; | ||
import { Log } from '../../schema'; | ||
import { translate } from '../../i18n'; | ||
import AlertIcon from '../AlertIcon'; | ||
import { KolButtonWcTag, KolHeadingWcTag } from '../../core/component-names'; | ||
|
||
export type KolAlertFcProps = JSXBase.HTMLAttributes<HTMLDivElement> & | ||
Partial<Omit<InternalAlertProps, 'on'>> & { | ||
onCloserClick?: () => void; | ||
onAlertTimeout?: () => void; | ||
}; | ||
|
||
const KolAlertFc: FC<KolAlertFcProps> = (props, children) => { | ||
const { class: classNames = {}, type = 'default', variant = 'msg', label, hasCloser, alert, onAlertTimeout, onCloserClick, level, ...other } = props; | ||
|
||
if (alert) { | ||
/** | ||
* - https://developer.mozilla.org/de/docs/Web/API/Navigator/vibrate | ||
* - https://googlechrome.github.io/samples/vibration/ | ||
*/ | ||
try { | ||
Log.debug(['Navigator should vibrate ...', navigator.vibrate([100, 75, 100, 75, 100])]); | ||
} catch (e) { | ||
Log.debug('Navigator does not support vibration.'); | ||
} | ||
|
||
setTimeout(() => { | ||
onAlertTimeout?.(); | ||
}, 10000); | ||
} | ||
|
||
const rootProps: Partial<JSXBase.HTMLAttributes<HTMLDivElement>> = { | ||
class: clsx('kol-alert-wc', 'alert', type, variant, { hasCloser: !!hasCloser }, classNames), | ||
role: alert ? 'alert' : undefined, | ||
...other, | ||
}; | ||
|
||
return ( | ||
<div {...rootProps}> | ||
<div class="heading"> | ||
<AlertIcon label={label} type={type} /> | ||
<div class="heading-content"> | ||
{label ? <KolHeadingWcTag _label={label} _level={level} /> : null} | ||
{variant === 'msg' && <div class="content">{children}</div>} | ||
</div> | ||
{hasCloser && ( | ||
<KolButtonWcTag | ||
class="close" | ||
_ariaDescription={label?.trim() || ''} | ||
_hideLabel | ||
_icons={{ | ||
left: { | ||
icon: 'codicon codicon-close', | ||
}, | ||
}} | ||
_label={translate('kol-close-alert')} | ||
_on={{ onClick: onCloserClick }} | ||
_tooltipAlign="left" | ||
></KolButtonWcTag> | ||
)} | ||
</div> | ||
{variant === 'card' && <div class="content">{children}</div>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default KolAlertFc; |
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 @@ | ||
export { default } from './Alert'; | ||
export * from './Alert'; |
12 changes: 12 additions & 0 deletions
12
...ages/components/src/functional-components/Alert/test/__snapshots__/snapshot.test.tsx.snap
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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KolAlertFc should render 1`] = ` | ||
<div class="alert default kol-alert-wc msg"> | ||
<div class="heading"> | ||
<kol-icon _icons="codicon codicon-comment" _label="kol-message" class="heading-icon"></kol-icon> | ||
<div class="heading-content"> | ||
<div class="content"></div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/components/src/functional-components/Alert/test/snapshot.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,11 @@ | ||
import { h } from '@stencil/core'; | ||
import KolAlertFc from './..'; | ||
import { renderFunctionalComponentToSpecPage } from '../../../utils/testing'; | ||
|
||
describe('KolAlertFc', () => { | ||
it('should render', async () => { | ||
const page = await renderFunctionalComponentToSpecPage(() => <KolAlertFc />); | ||
|
||
expect(page.root).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.