-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
1 parent
cc2138b
commit 6450bec
Showing
10 changed files
with
187 additions
and
2 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
35 changes: 35 additions & 0 deletions
35
packages/volto/src/components/manage/Widgets/StaticTextWidget.jsx
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 @@ | ||
import { useRef } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import FormFieldWrapper from '@plone/volto/components/manage/Widgets/FormFieldWrapper'; | ||
|
||
const StaticTextWidget = (props) => { | ||
const { id, value } = props; | ||
|
||
return ( | ||
<FormFieldWrapper {...props} className="text" columns={1}> | ||
<div id={id} className="wrapper"> | ||
<p | ||
dangerouslySetInnerHTML={{ | ||
__html: value?.data || '', | ||
}} | ||
/> | ||
</div> | ||
</FormFieldWrapper> | ||
); | ||
}; | ||
|
||
export default StaticTextWidget; | ||
|
||
StaticTextWidget.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
value: PropTypes.string, | ||
minLength: PropTypes.number, | ||
maxLength: PropTypes.number, | ||
}; | ||
|
||
StaticTextWidget.defaultProps = { | ||
value: null, | ||
minLength: null, | ||
maxLength: null, | ||
}; |
20 changes: 20 additions & 0 deletions
20
packages/volto/src/components/manage/Widgets/StaticTextWidget.stories.jsx
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,20 @@ | ||
import StaticTextWidget from './StaticTextWidget'; | ||
import WidgetStory from './story'; | ||
|
||
export const StaticText = WidgetStory.bind({ | ||
props: { id: 'text', title: 'Text' }, | ||
widget: StaticTextWidget, | ||
}); | ||
|
||
export default { | ||
title: 'Edit Widgets/Static Text', | ||
component: StaticTextWidget, | ||
decorators: [ | ||
(Story) => ( | ||
<div className="ui segment form attached" style={{ width: '400px' }}> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
argTypes: {}, | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/volto/src/components/manage/Widgets/StaticTextWidget.test.jsx
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 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import configureStore from 'redux-mock-store'; | ||
import { Provider } from 'react-intl-redux'; | ||
|
||
import StaticTextWidget from './StaticTextWidget'; | ||
|
||
const mockStore = configureStore(); | ||
|
||
test('renders a text widget component', () => { | ||
const store = mockStore({ | ||
intl: { | ||
locale: 'en', | ||
messages: {}, | ||
}, | ||
}); | ||
|
||
const component = renderer.create( | ||
<Provider store={store}> | ||
<StaticTextWidget id="my-field" /> | ||
</Provider>, | ||
); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); |
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
16 changes: 16 additions & 0 deletions
16
packages/volto/src/components/theme/Widgets/StaticTextWidget.jsx
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,16 @@ | ||
import React from 'react'; | ||
import cx from 'classnames'; | ||
|
||
const StaticTextWidget = ({ value, className }) => | ||
value ? ( | ||
<p | ||
className={cx(className, 'statictext', 'widget')} | ||
dangerouslySetInnerHTML={{ | ||
__html: value.data, | ||
}} | ||
/> | ||
) : ( | ||
'' | ||
); | ||
|
||
export default StaticTextWidget; |
29 changes: 29 additions & 0 deletions
29
packages/volto/src/components/theme/Widgets/StaticTextWidget.stories.jsx
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,29 @@ | ||
import React from 'react'; | ||
import StaticTextWidget from './StaticTextWidget'; | ||
import Wrapper from '@plone/volto/storybook'; | ||
|
||
const StaticTextWidgetComponent = ({ children, className, value }) => { | ||
return ( | ||
<Wrapper location={{ pathname: '/folder2/folder21/doc212' }}> | ||
<div className="ui segment form attached" style={{ width: '400px' }}> | ||
<StaticTextWidget | ||
value={value} | ||
children={children} | ||
className={className} | ||
/> | ||
</div> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export const StaticText = StaticTextWidgetComponent.bind({}); | ||
StaticTextWidget.args = { | ||
value: { data: '<p><strong>Hello</strong> <em>world</em></p>' }, | ||
className: '', | ||
}; | ||
|
||
export default { | ||
title: 'View Widgets/Static Text', | ||
component: StaticTextWidget, | ||
argTypes: {}, | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/volto/src/components/theme/Widgets/StaticTextWidget.test.js
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 React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import StaticTextWidget from './StaticTextWidget'; | ||
|
||
describe('StaticTextWidget', () => { | ||
it('renders an empty static text view widget component', () => { | ||
const component = renderer.create(<StaticTextWidget />); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders a static text view widget component', () => { | ||
const component = renderer.create( | ||
<StaticTextWidget | ||
className="metadata" | ||
value={{ data: '<b>Foo bar</b>' }} | ||
/>, | ||
); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders a static text view widget component with children', () => { | ||
const component = renderer.create( | ||
<StaticTextWidget className="metadata" value={{ data: '<b>Foo bar</b>' }}> | ||
{(child) => <strong>{child}</strong>} | ||
</StaticTextWidget>, | ||
); | ||
const json = component.toJSON(); | ||
expect(json).toMatchSnapshot(); | ||
}); | ||
}); |
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