-
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.
feat: pos-value element to render any predicate value
- Loading branch information
Showing
8 changed files
with
146 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# pos-value | ||
|
||
Render a value for a given predicate | ||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| ----------- | ----------- | ------------------------------------------ | -------- | ----------- | | ||
| `predicate` | `predicate` | URI of the predicate to get the value from | `string` | `undefined` | | ||
|
||
|
||
## Events | ||
|
||
| Event | Description | Type | | ||
| ----------------- | ----------- | ------------------ | | ||
| `pod-os:resource` | | `CustomEvent<any>` | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { PosValue } from './pos-value'; | ||
|
||
describe('pos-value', () => { | ||
it('is empty initially', async () => { | ||
const page = await newSpecPage({ | ||
components: [PosValue], | ||
html: `<pos-value predicate="https://vocab.example/#term" />`, | ||
}); | ||
expect(page.root).toEqualHtml(` | ||
<pos-value predicate="https://vocab.example/#term" /> | ||
<mock:shadow-root></mock:shadow-root> | ||
</pos-value> | ||
`); | ||
}); | ||
|
||
it('renders property value from resource', async () => { | ||
const page = await newSpecPage({ | ||
components: [PosValue], | ||
html: `<pos-value predicate="https://vocab.example/#term" />`, | ||
}); | ||
await page.rootInstance.receiveResource({ | ||
anyValue: uri => `value of ${uri}`, | ||
}); | ||
await page.waitForChanges(); | ||
expect(page.root).toEqualHtml(` | ||
<pos-value predicate="https://vocab.example/#term" /> | ||
<mock:shadow-root>value of https://vocab.example/#term</mock:shadow-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,30 @@ | ||
import { Thing } from '@pod-os/core'; | ||
import { Component, Event, Prop, State } from '@stencil/core'; | ||
import { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware'; | ||
|
||
@Component({ | ||
tag: 'pos-value', | ||
shadow: true, | ||
}) | ||
export class PosValue implements ResourceAware { | ||
/** | ||
* URI of the predicate to get the value from | ||
*/ | ||
@Prop() predicate: string; | ||
@State() resource: Thing; | ||
|
||
@Event({ eventName: 'pod-os:resource' }) | ||
subscribeResource: ResourceEventEmitter; | ||
|
||
componentWillLoad() { | ||
subscribeResource(this); | ||
} | ||
|
||
receiveResource = (resource: Thing) => { | ||
this.resource = resource; | ||
}; | ||
|
||
render() { | ||
return this.resource ? this.resource.anyValue(this.predicate) : null; | ||
} | ||
} |
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,30 @@ | ||
import {html} from "lit-html"; | ||
|
||
import { | ||
Canvas, | ||
Meta, | ||
Story | ||
} from '@storybook/addon-docs/blocks'; | ||
|
||
<Meta | ||
title="Values" | ||
args={{subject: "https://solidproject.solidcommunity.net/profile/card#me", predicate: "http://www.w3.org/2006/vcard/ns#role"}} | ||
/> | ||
|
||
|
||
## pos-value | ||
|
||
Renders any value for the given predicate of the resource. | ||
|
||
<Canvas | ||
withSource="open"> | ||
<Story | ||
name="pos-value" | ||
> | ||
{({subject, predicate}) => html` | ||
<pos-resource uri=${subject}> | ||
<pos-value predicate=${predicate}/> | ||
</pos-resource> | ||
`} | ||
</Story> | ||
</Canvas> |
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