Skip to content

Commit

Permalink
Merge branch 'main' of github.com:askorama/orama-ui-components
Browse files Browse the repository at this point in the history
  • Loading branch information
g-francesca committed Jul 4, 2024
2 parents efad4dd + d6c7cbf commit 8181ed9
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 85 deletions.
19 changes: 19 additions & 0 deletions apps/storybook/stories/orama-chat.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { StoryObj, Meta } from '@storybook/web-components'

const meta: Meta = {
title: 'Internal/OramaChat',
component: 'orama-chat'
}

export default meta
type Story = StoryObj

const Template = (args) => {
return `<orama-chat ${{...args}}></orama-chat>`
}

// More on writing stories with args: https://storybook.js.org/docs/html/writing-stories/args
export const Primary: Story = {
render: Template,
args: {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ import { ProxyCmp } from './angular-component-lib/utils';
import { Components } from 'orama-ui';


@ProxyCmp({
})
@Component({
selector: 'orama-chat',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [],
})
export class OramaChat {
protected el: HTMLElement;
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
c.detach();
this.el = r.nativeElement;
}
}


export declare interface OramaChat extends Components.OramaChat {}


@ProxyCmp({
inputs: ['as']
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as d from './components';

export const DIRECTIVES = [
d.OramaChat,
d.OramaParagraph,
d.SearchBox
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import type { JSX } from 'orama-ui';



export const OramaChat = /*@__PURE__*/createReactComponent<JSX.OramaChat, HTMLOramaChatElement>('orama-chat');
export const OramaParagraph = /*@__PURE__*/createReactComponent<JSX.OramaParagraph, HTMLOramaParagraphElement>('orama-paragraph');
export const SearchBox = /*@__PURE__*/createReactComponent<JSX.SearchBox, HTMLSearchBoxElement>('search-box');
3 changes: 3 additions & 0 deletions packages/ui-stencil-vue/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { JSX } from 'orama-ui';



export const OramaChat = /*@__PURE__*/ defineContainer<JSX.OramaChat>('orama-chat', undefined);


export const OramaParagraph = /*@__PURE__*/ defineContainer<JSX.OramaParagraph>('orama-paragraph', undefined, [
'as'
]);
Expand Down
91 changes: 45 additions & 46 deletions packages/ui-stencil/package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
{
"name": "ui-stencil",
"version": "0.0.1",
"description": "Stencil Component Starter",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ionic-team/stencil-component-starter.git"
},
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"files": [
"dist/",
"loader/"
],
"scripts": {
"build": "stencil build --docs",
"clean": "rm -rf node_modules .turbo dist .stencil loader www",
"dev": "stencil build --watch",
"generate": "stencil generate",
"start": "stencil build --dev --watch --serve",
"test": "stencil test --spec --e2e",
"test.watch": "stencil test --spec --e2e --watchAll"
},
"types": "dist/types/index.d.ts",
"dependencies": {
"@stencil/core": "^4.19.0",
"@stencil/store": "^2.0.16"
},
"devDependencies": {
"@stencil-community/postcss": "^2.2.0",
"@stencil/angular-output-target": "^0.8.4",
"@stencil/react-output-target": "^0.5.3",
"@stencil/sass": "^3.0.12",
"@stencil/vue-output-target": "^0.8.8",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"puppeteer": "^22.12.1",
"sass-loader": "^14.2.1"
},
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"es2015": "dist/esm/index.mjs",
"es2017": "dist/esm/index.mjs",
"unpkg": "dist/ui-stencil/ui-stencil.esm.js"
"name": "ui-stencil",
"version": "0.0.1",
"description": "Stencil Component Starter",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ionic-team/stencil-component-starter.git"
},
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"files": ["dist/", "loader/"],
"scripts": {
"build": "stencil build --docs",
"clean": "rm -rf node_modules .turbo dist .stencil loader www",
"dev": "stencil build --watch",
"generate": "stencil generate",
"start": "stencil build --dev --watch --serve",
"test": "stencil test --spec --e2e",
"test.watch": "stencil test --spec --e2e --watchAll"
},
"types": "dist/types/index.d.ts",
"dependencies": {
"@oramacloud/client": "1.3.2",
"@stencil/core": "^4.19.0",
"@stencil/store": "^2.0.16",
"sse.js": "^2.5.0"
},
"devDependencies": {
"@stencil/store": "^2.0.16",
"@stencil/angular-output-target": "^0.8.4",
"@stencil/react-output-target": "^0.5.3",
"@stencil/vue-output-target": "^0.8.8",
"@stencil/sass": "^3.0.12",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"puppeteer": "^22.12.1",
"sass-loader": "^14.2.1"
},
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"es2015": "dist/esm/index.mjs",
"es2017": "dist/esm/index.mjs",
"unpkg": "dist/ui-stencil/ui-stencil.esm.js"
}
19 changes: 17 additions & 2 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { ParagraphProps } from "./components/internal/Typography/Paragraph";
export { ParagraphProps } from "./components/internal/Typography/Paragraph";
export namespace Components {
interface OramaChat {
}
interface OramaParagraph {
"as"?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
"as"?: ParagraphProps['as'];
}
interface SearchBox {
"color": 'dark' | 'light' | 'system';
"themeConfig": { colors: { light: { primaryColor: string }; dark: { primaryColor: string } } };
}
}
declare global {
interface HTMLOramaChatElement extends Components.OramaChat, HTMLStencilElement {
}
var HTMLOramaChatElement: {
prototype: HTMLOramaChatElement;
new (): HTMLOramaChatElement;
};
interface HTMLOramaParagraphElement extends Components.OramaParagraph, HTMLStencilElement {
}
var HTMLOramaParagraphElement: {
Expand All @@ -28,19 +38,23 @@ declare global {
new (): HTMLSearchBoxElement;
};
interface HTMLElementTagNameMap {
"orama-chat": HTMLOramaChatElement;
"orama-paragraph": HTMLOramaParagraphElement;
"search-box": HTMLSearchBoxElement;
}
}
declare namespace LocalJSX {
interface OramaChat {
}
interface OramaParagraph {
"as"?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
"as"?: ParagraphProps['as'];
}
interface SearchBox {
"color"?: 'dark' | 'light' | 'system';
"themeConfig"?: { colors: { light: { primaryColor: string }; dark: { primaryColor: string } } };
}
interface IntrinsicElements {
"orama-chat": OramaChat;
"orama-paragraph": OramaParagraph;
"search-box": SearchBox;
}
Expand All @@ -49,6 +63,7 @@ export { LocalJSX as JSX };
declare module "@stencil/core" {
export namespace JSX {
interface IntrinsicElements {
"orama-chat": LocalJSX.OramaChat & JSXBase.HTMLAttributes<HTMLOramaChatElement>;
"orama-paragraph": LocalJSX.OramaParagraph & JSXBase.HTMLAttributes<HTMLOramaParagraphElement>;
"search-box": LocalJSX.SearchBox & JSXBase.HTMLAttributes<HTMLSearchBoxElement>;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-stencil/src/components/SearchBox/SearchBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Host, Prop, h } from '@stencil/core'
import { sassVariables } from '../../config/colors';
import { sassVariables } from '../../config/colors'

@Component({
tag: 'search-box',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Component, Prop, h } from '@stencil/core';
export interface ParagraphProps {
as?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
as?: 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | 'small';
}
@Component({
tag: 'orama-paragraph',
styleUrl: 'typography.scss',
})

export class Paragraph implements ParagraphProps {
@Prop() as?: 'span' | 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
@Prop() as?: ParagraphProps['as']

render() {
const Tag = this.as || 'p';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

## Properties

| Property | Attribute | Description | Type | Default |
| -------- | --------- | ----------- | --------------------------------------------------------------- | ----------- |
| `as` | `as` | | `"h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "p" \| "span"` | `undefined` |
| Property | Attribute | Description | Type | Default |
| -------- | --------- | ----------- | -------------------------------------------------------------------------- | ----------- |
| `as` | `as` | | `"h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "p" \| "small" \| "span"` | `undefined` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.paragraph {
color: var(--text-color-secondary, text-color('secondary'));
font-size: var(--font-size-md, $font-size-md);
line-height: var(--font-line-height-m, 1.5);
line-height: var(--font-line-height-m, $font-line-height-m);

&--bold {
font-weight: var(--font-weight-semibold, 600);
font-weight: var(--font-weight-semibold, $font-weight-semibold);
}

@media (--md-min) {
Expand All @@ -15,10 +15,10 @@
.span {
color: var(--text-color-tertiary, text-color('tertiary'));
font-size: var(--font-size-sm, $font-size-sm);
line-height: var(--font-line-height-m, 1.25);
line-height: var(--font-line-height-s, $font-line-height-s);

&--bold {
font-weight: var(--font-weight-semibold, 600);
font-weight: var(--font-weight-semibold, $font-weight-semibold);
}

@media (--md-min) {
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-stencil/src/components/orama-chat/orama-chat.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:host
display: block
70 changes: 70 additions & 0 deletions packages/ui-stencil/src/components/orama-chat/orama-chat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Component, Host, State, h } from '@stencil/core'
import { OramaClient } from '@oramacloud/client'
import { ChatService } from '../../services/ChatService'
import { chatContext } from '../../context/chatContext'

@Component({
tag: 'orama-chat',
styleUrl: 'orama-chat.sass',
shadow: true
})
export class OramaChat {
@State() inputValue = ''

private chatService: ChatService

componentWillLoad() {
// TODO: Should not be hardcoded
const oramaClient = new OramaClient({
api_key: '6kHcoevr3zkbBmC2hHqlcNQrOgejS4ds',
endpoint: 'https://cloud.orama.run/v1/indexes/orama-docs-pgjign'
})

this.chatService = new ChatService(oramaClient)
}

handleSubmit = (e: Event) => {
e.preventDefault()

if (!this.chatService) {
throw new Error('Chat Service is not initialized')
}

this.chatService.sendQuestion(this.inputValue)
this.inputValue = ''
}

render() {
return (
<Host>
<form onSubmit={this.handleSubmit}>
<div>Is loading: {String(chatContext.isLoading)}</div>
<div>Is error: {String(chatContext.error)}</div>
<div style={{ display: 'flex' }}>
<input
autofocus
style={{ width: '100%' }}
type="text"
value={this.inputValue}
onInput={(e: Event) => (this.inputValue = (e.target as HTMLInputElement).value)}
/>
<button type="submit" onClick={this.handleSubmit}>
Ask
</button>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{chatContext.messages.map((message, index) => (
// biome-ignore lint/suspicious/noArrayIndexKey: There is not other key available form SDK right now
<div key={index} style={{ display: 'flex', flexDirection: 'column', gap: '32px' }}>
{/* TODO: We still do not have sources */}
<div>
<span>Content: </span> {message.content}
</div>
</div>
))}
</div>
</form>
</Host>
)
}
}
10 changes: 10 additions & 0 deletions packages/ui-stencil/src/components/orama-chat/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# orama-chat



<!-- Auto Generated Below -->


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
23 changes: 23 additions & 0 deletions packages/ui-stencil/src/context/chatContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createStore } from '@stencil/store'

// TODO: Seems like there is no message type being exported from orama-client rn
// export type TChatMessageBlock = {
// type: 'text' | 'component' | 'sources'
// received?: boolean
// content: string
// }

export type TChatMessage = {
role: 'user' | 'assistant'
content: string
// messageBlocks: TChatMessageBlock[]
}

const { state: chatContext } = createStore({
messages: [] as TChatMessage[],
isLoading: false,
// TODO: Evaluate if we need to have a error object/string instead of just a boolean
error: false
})

export { chatContext }
Loading

0 comments on commit 8181ed9

Please sign in to comment.