forked from opensearch-project/oui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schema-item (opensearch-project#974)
* Adds SchemaItem Signed-off-by: Ashwin P Chandran <[email protected]> * updates snapshot Signed-off-by: Ashwin P Chandran <[email protected]> * Adds changelog entry Signed-off-by: Ashwin P Chandran <[email protected]> * push fix changelog Signed-off-by: Ashwin P Chandran <[email protected]> * Address PR comments Signed-off-by: Ashwin P Chandran <[email protected]> --------- Signed-off-by: Ashwin P Chandran <[email protected]>
- Loading branch information
Showing
13 changed files
with
577 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { OuiSchemaItem } from '../../../../src/components/schema'; | ||
import { OuiSpacer } from '../../../../src/components/spacer'; | ||
|
||
export default () => ( | ||
<> | ||
<OuiSchemaItem label="Simple" /> | ||
<OuiSchemaItem iconType="tokenString" label="Simple with icon" /> | ||
<OuiSchemaItem | ||
iconType="tokenShape" | ||
label="Icon and actions" | ||
actions={[ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger', | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top', | ||
delay: 'long', | ||
}, | ||
}, | ||
]} | ||
/> | ||
<OuiSchemaItem | ||
iconType="tokenShape" | ||
label="Compressed with icon and actions" | ||
actions={[ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger', | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top', | ||
delay: 'long', | ||
}, | ||
}, | ||
]} | ||
compressed | ||
/> | ||
<OuiSpacer /> | ||
<OuiSchemaItem | ||
iconType="tokenShape" | ||
label="With a panel" | ||
actions={[ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger', | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top', | ||
delay: 'long', | ||
}, | ||
}, | ||
]} | ||
withPanel | ||
/> | ||
<OuiSpacer /> | ||
<OuiSchemaItem | ||
iconType="tokenShape" | ||
label="With a panel and compressed" | ||
actions={[ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger', | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top', | ||
delay: 'long', | ||
}, | ||
}, | ||
]} | ||
withPanel | ||
compressed | ||
/> | ||
<OuiSpacer /> | ||
<div style={{ width: '300px' }}> | ||
<OuiSchemaItem | ||
iconType="tokenShape" | ||
label="A very long label that will wrap with a panel for good measure" | ||
actions={[ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger', | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top', | ||
delay: 'long', | ||
}, | ||
}, | ||
]} | ||
withPanel | ||
/> | ||
</div> | ||
</> | ||
); |
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,73 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { GuideSectionTypes } from '../../components'; | ||
|
||
import { OuiSchemaItem } from '../../../../src/components'; | ||
|
||
import Schema from './schema'; | ||
const schemaSource = require('!!raw-loader!./schema'); | ||
const schemaHtml = renderToHtml(Schema); | ||
|
||
import SchemaGroup from './schema_group'; | ||
const schemaGroupSource = require('!!raw-loader!./schema'); | ||
const schemaGroupHtml = renderToHtml(Schema); | ||
|
||
export const SchemaExample = { | ||
title: 'Schema', | ||
isExperimental: true, | ||
sections: [ | ||
{ | ||
source: [ | ||
{ | ||
type: GuideSectionTypes.JS, | ||
code: schemaSource, | ||
}, | ||
{ | ||
type: GuideSectionTypes.HTML, | ||
code: schemaHtml.render(), | ||
}, | ||
], | ||
text: ( | ||
<p> | ||
This is the basic <strong>OuiSchemaItem</strong> component. | ||
</p> | ||
), | ||
props: { OuiSchemaItem }, | ||
demo: <Schema />, | ||
}, | ||
{ | ||
title: 'SchemaItem as a list', | ||
source: [ | ||
{ | ||
type: GuideSectionTypes.JS, | ||
code: schemaGroupSource, | ||
}, | ||
{ | ||
type: GuideSectionTypes.HTML, | ||
code: schemaGroupHtml, | ||
}, | ||
], | ||
text: ( | ||
<p> | ||
Grouping <strong>OuiSchemaItem</strong> with{' '} | ||
<strong>OuiFlexGroup</strong> to make a list. | ||
</p> | ||
), | ||
props: { OuiSchemaItem }, | ||
demo: <SchemaGroup />, | ||
}, | ||
], | ||
}; |
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,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { OuiSchemaItem } from '../../../../src/components/schema'; | ||
import { OuiFlexGroup, OuiFlexItem } from '../../../../src/components/flex'; | ||
import { OuiSpacer } from '../../../../src/components/spacer'; | ||
|
||
export default () => { | ||
const actions = [ | ||
{ | ||
iconType: 'trash', | ||
'aria-label': 'Delete', | ||
onClick: () => {}, | ||
color: 'danger' as const, | ||
}, | ||
{ | ||
iconType: 'pencil', | ||
'aria-label': 'Edit', | ||
onClick: () => {}, | ||
tooltip: { | ||
content: 'Edit', | ||
position: 'top' as const, | ||
delay: 'long' as const, | ||
}, | ||
}, | ||
]; | ||
|
||
const items = Array.from({ length: 5 }, (_, i) => ({ | ||
key: `item${i}`, | ||
iconType: 'tokenShape', | ||
label: `Item no ${i + 1}`, | ||
actions, | ||
})); | ||
|
||
items.push({ | ||
key: 'last', | ||
iconType: 'tokenShape', | ||
label: 'Item with a really long label that will wrap', | ||
actions, | ||
}); | ||
|
||
return ( | ||
<> | ||
<p>As a list</p> | ||
<OuiSpacer size="m" /> | ||
<OuiFlexGroup | ||
style={{ width: '300px' }} | ||
direction="column" | ||
gutterSize="none"> | ||
{items.map((item) => ( | ||
<OuiFlexItem> | ||
<OuiSchemaItem {...item} compressed /> | ||
</OuiFlexItem> | ||
))} | ||
</OuiFlexGroup> | ||
<OuiSpacer size="m" /> | ||
<p>With panels</p> | ||
<OuiSpacer size="m" /> | ||
<OuiFlexGroup | ||
style={{ width: '300px' }} | ||
direction="column" | ||
gutterSize="s"> | ||
{items.map((item) => ( | ||
<OuiFlexItem> | ||
<OuiSchemaItem {...item} withPanel /> | ||
</OuiFlexItem> | ||
))} | ||
</OuiFlexGroup> | ||
</> | ||
); | ||
}; |
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
35 changes: 35 additions & 0 deletions
35
src/components/schema/__snapshots__/schema_item.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,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`OuiSchema is rendered 1`] = ` | ||
<div | ||
aria-label="aria-label" | ||
class="ouiSchemaItem testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
<div | ||
class="ouiSchemaItem__label" | ||
> | ||
Test | ||
</div> | ||
<div | ||
class="ouiSchemaItem__actions" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`OuiSchema it renders compressed correctly 1`] = ` | ||
<div | ||
aria-label="aria-label" | ||
class="ouiSchemaItem ouiSchemaItem--compressed testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
> | ||
<div | ||
class="ouiSchemaItem__label" | ||
> | ||
Test | ||
</div> | ||
<div | ||
class="ouiSchemaItem__actions" | ||
/> | ||
</div> | ||
`; |
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 @@ | ||
/*! | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
@import 'schema_item'; |
Oops, something went wrong.