-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ai][assistant] Create AI Assistant Icon, Avatar, Beacon
- Loading branch information
1 parent
cebcf01
commit 937fed4
Showing
50 changed files
with
508 additions
and
617 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
Validating CODEOWNERS rules …
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
# @kbn/ai-assistant-icon | ||
|
||
Empty package generated by @kbn/generate |
34 changes: 34 additions & 0 deletions
34
x-pack/packages/ai-assistant/icon/__stories__/avatar.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { AssistantAvatar as Component } from '../avatar'; | ||
|
||
export default { | ||
title: 'Assistant Icon/Avatar', | ||
component: Component, | ||
argTypes: { | ||
iconSize: { | ||
control: 'select', | ||
options: ['original', 's', 'm', 'l', 'xl', 'xxl', undefined], | ||
defaultValue: undefined, | ||
}, | ||
size: { | ||
control: 'select', | ||
options: ['s', 'm', 'l', 'xl', undefined], | ||
defaultValue: undefined, | ||
}, | ||
name: { | ||
control: 'text', | ||
defaultValue: 'Elastic Assistant', | ||
}, | ||
}, | ||
} as ComponentMeta<typeof Component>; | ||
|
||
export const Avatar: ComponentStory<typeof Component> = (args) => <Component {...args} />; |
25 changes: 25 additions & 0 deletions
25
x-pack/packages/ai-assistant/icon/__stories__/beacon.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,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { AssistantBeacon as Component } from '../beacon'; | ||
|
||
export default { | ||
title: 'Assistant Icon/Beacon', | ||
component: Component, | ||
argTypes: { | ||
size: { | ||
control: 'select', | ||
options: ['original', 's', 'm', 'l', 'xl', 'xxl'], | ||
defaultValue: 'xxl', | ||
}, | ||
}, | ||
} as ComponentMeta<typeof Component>; | ||
|
||
export const Beacon: ComponentStory<typeof Component> = (args) => <Component {...args} />; |
25 changes: 25 additions & 0 deletions
25
x-pack/packages/ai-assistant/icon/__stories__/icon.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,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { AssistantIcon as Component } from '../icon'; | ||
|
||
export default { | ||
title: 'Assistant Icon/Icon', | ||
component: Component, | ||
argTypes: { | ||
size: { | ||
control: 'select', | ||
options: ['original', 's', 'm', 'l', 'xl', 'xxl'], | ||
defaultValue: 'xxl', | ||
}, | ||
}, | ||
} as ComponentMeta<typeof Component>; | ||
|
||
export const Icon: ComponentStory<typeof Component> = (args) => <Component {...args} />; |
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,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEuiTheme } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
|
||
export const useStyles = () => { | ||
const { | ||
euiTheme: { border, size }, | ||
} = useEuiTheme(); | ||
|
||
const root = css` | ||
border: ${border.thin}; | ||
padding: ${size.xs}; | ||
`; | ||
|
||
return { root }; | ||
}; |
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,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiAvatar, EuiAvatarProps } from '@elastic/eui'; | ||
|
||
import { AssistantIcon } from './icon'; | ||
import { useStyles } from './avatar.styles'; | ||
|
||
/** | ||
* Avatar component for the AI Assistant. | ||
*/ | ||
export type AssistantAvatarProps = Omit< | ||
EuiAvatarProps, | ||
'iconType' | 'initials' | 'initialsLength' | 'imageUrl' | ||
>; | ||
|
||
/** | ||
* A `EuiAvatar` component customized for the AI Assistant. | ||
*/ | ||
export const AssistantAvatar = ({ | ||
css, | ||
color = 'plain', | ||
size = 'm', | ||
...props | ||
}: AssistantAvatarProps) => { | ||
const { root } = useStyles(); | ||
return <EuiAvatar {...{ ...props, color, size }} css={[root, css]} iconType={AssistantIcon} />; | ||
}; |
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,138 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEuiTheme } from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import { AssistantBeaconProps } from './beacon'; | ||
|
||
/** | ||
* Returns contextually-relevant styles for the AI Assistant beacon. | ||
*/ | ||
export const useStyles = ({ | ||
backgroundColor = 'body', | ||
size: iconSize = 'xxl', | ||
}: AssistantBeaconProps) => { | ||
const { | ||
euiTheme: { colors, size }, | ||
} = useEuiTheme(); | ||
|
||
const background = colors[backgroundColor]; | ||
const rootSize = size[iconSize]; | ||
|
||
const root = css` | ||
// Distance between the icon and the ring | ||
--ring-padding: ${Math.max(parseInt(rootSize, 10) / 2, parseInt(size.m, 10))}px; | ||
--ring-size: calc(${rootSize} + var(--ring-padding)); | ||
// Size of the mask that hides the ring at frame 0 | ||
--mask-point: calc(var(--ring-size) + 1px); | ||
// Overall size of the icon, given the animation doubles the | ||
// ring size at its end. | ||
--root-size: calc(var(--ring-size) * 2); | ||
background-color: ${background}; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: relative; | ||
width: var(--root-size); | ||
height: var(--root-size); | ||
&:after { | ||
content: ''; | ||
position: absolute; | ||
height: var(--mask-point); | ||
width: var(--mask-point); | ||
z-index: 2; | ||
border: 2px solid ${background}; | ||
border-radius: 50%; | ||
} | ||
`; | ||
|
||
const rings = css` | ||
display: inline-block; | ||
position: absolute; | ||
height: var(--ring-size); | ||
width: var(--ring-size); | ||
@keyframes outer { | ||
0% { | ||
opacity: 1; | ||
transform: scaleY(1) scaleX(1); | ||
} | ||
20% { | ||
opacity: 0.5; | ||
} | ||
70% { | ||
opacity: 0.2; | ||
transform: scaleY(2) scaleX(2); | ||
} | ||
80% { | ||
opacity: 0; | ||
transform: scaleY(2) scaleX(2); | ||
} | ||
90% { | ||
opacity: 0; | ||
transform: scaleY(1) scaleX(1); | ||
} | ||
} | ||
@keyframes inner { | ||
0% { | ||
opacity: 1; | ||
transform: scaleY(1) scaleX(1); | ||
} | ||
15% { | ||
opacity: 1; | ||
transform: scaleY(1) scaleX(1); | ||
} | ||
40% { | ||
opacity: 0.5; | ||
} | ||
70% { | ||
opacity: 0.2; | ||
transform: scaleY(1.5) scaleX(1.5); | ||
} | ||
80% { | ||
opacity: 0; | ||
transform: scaleY(1.5) scaleX(1.5); | ||
} | ||
90% { | ||
opacity: 0; | ||
transform: scaleY(1) scaleX(1); | ||
} | ||
} | ||
&:before, | ||
&:after { | ||
content: ''; | ||
position: absolute; | ||
width: var(--ring-size); | ||
height: var(--ring-size); | ||
top: 0; | ||
left: 0; | ||
z-index: 0; | ||
border: 1px solid ${colors.primary}; | ||
border-radius: 50%; | ||
animation: 4s cubic-bezier(0.42, 0, 0.37, 1) 0.5s infinite normal none running; | ||
} | ||
&:before { | ||
animation-name: inner; | ||
} | ||
&:after { | ||
animation-name: outer; | ||
} | ||
`; | ||
|
||
return { | ||
root, | ||
rings, | ||
}; | ||
}; |
Oops, something went wrong.