-
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.
- Loading branch information
Showing
23 changed files
with
1,451 additions
and
17 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
70 changes: 70 additions & 0 deletions
70
src/components/manage/Blocks/DiscodataComponents/Button/Edit.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,70 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import _uniqueId from 'lodash/uniqueId'; | ||
import RenderFields from 'volto-addons/Widgets/RenderFields'; | ||
import View from './View'; | ||
import { settings } from '~/config'; | ||
|
||
const getSchema = (props) => { | ||
return { | ||
queryParam: { | ||
title: 'Query parameter', | ||
type: 'text', | ||
}, | ||
visible: { | ||
title: 'Visible when', | ||
type: 'array', | ||
choices: [ | ||
['hasQuery', 'Query parameter exists'], | ||
['always', 'Always'], | ||
], | ||
}, | ||
leftText: { | ||
title: 'Left text', | ||
widget: 'textarea', | ||
}, | ||
rightText: { | ||
title: 'Right text', | ||
widget: 'textarea', | ||
}, | ||
color: { | ||
title: 'Color', | ||
type: 'text', | ||
}, | ||
component: { | ||
title: 'Component type', | ||
type: 'array', | ||
choices: [ | ||
['h1', 'H1'], | ||
['h2', 'H2'], | ||
['h3', 'H3'], | ||
['p', 'Paragraph'], | ||
], | ||
}, | ||
}; | ||
}; | ||
|
||
const Edit = (props) => { | ||
const [state, setState] = useState({ | ||
schema: getSchema({ ...props, providerUrl: settings.providerUrl }), | ||
id: _uniqueId('block_'), | ||
}); | ||
return ( | ||
<div> | ||
<RenderFields | ||
schema={state.schema} | ||
{...props} | ||
title="Query param text block" | ||
noValueKey={true} | ||
/> | ||
<View {...props} id={state.id} mode="edit" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
pathname: state.router.location.pathname, | ||
})), | ||
)(Edit); |
78 changes: 78 additions & 0 deletions
78
src/components/manage/Blocks/DiscodataComponents/Button/View.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,78 @@ | ||
/* REACT */ | ||
import React, { useState } from 'react'; | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
|
||
function isColor(strColor) { | ||
return /^#[0-9A-F]{6}$/i.test(strColor); | ||
} | ||
|
||
const components = { | ||
h1: (text, color) => ( | ||
<h1 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h1> | ||
), | ||
h2: (text, color) => ( | ||
<h2 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h2> | ||
), | ||
h3: (text, color) => ( | ||
<h3 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h3> | ||
), | ||
p: (text, color) => ( | ||
<p className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</p> | ||
), | ||
}; | ||
|
||
const View = ({ content, ...props }) => { | ||
const { data } = props; | ||
const { | ||
visible = 'always', | ||
component = 'h1', | ||
queryParam = '', | ||
leftText = '', | ||
rightText = '', | ||
color = '#000', | ||
} = data; | ||
|
||
const queryText = props.search[queryParam] || ''; | ||
|
||
const text = `${leftText} ${queryText} ${rightText}`; | ||
|
||
const hasText = leftText || queryText || rightText; | ||
|
||
const textMayRender = | ||
(visible === 'always' && hasText) || (visible === 'hasQuery' && queryText); | ||
|
||
return ( | ||
<> | ||
{props.mode === 'edit' ? ( | ||
!textMayRender ? ( | ||
<p>Query param text</p> | ||
) : ( | ||
'' | ||
) | ||
) : ( | ||
'' | ||
)} | ||
{textMayRender && components[component] | ||
? components[component](text, isColor(color) ? color : '#000') | ||
: ''} | ||
</> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
query: state.router.location.search, | ||
content: | ||
state.prefetch?.[state.router.location.pathname] || state.content.data, | ||
search: state.discodata_query.search, | ||
})), | ||
)(View); |
70 changes: 70 additions & 0 deletions
70
src/components/manage/Blocks/DiscodataComponents/Link/Edit.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,70 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { compose } from 'redux'; | ||
import _uniqueId from 'lodash/uniqueId'; | ||
import RenderFields from 'volto-addons/Widgets/RenderFields'; | ||
import View from './View'; | ||
import { settings } from '~/config'; | ||
|
||
const getSchema = (props) => { | ||
return { | ||
queryParam: { | ||
title: 'Query parameter', | ||
type: 'text', | ||
}, | ||
visible: { | ||
title: 'Visible when', | ||
type: 'array', | ||
choices: [ | ||
['hasQuery', 'Query parameter exists'], | ||
['always', 'Always'], | ||
], | ||
}, | ||
leftText: { | ||
title: 'Left text', | ||
widget: 'textarea', | ||
}, | ||
rightText: { | ||
title: 'Right text', | ||
widget: 'textarea', | ||
}, | ||
color: { | ||
title: 'Color', | ||
type: 'text', | ||
}, | ||
component: { | ||
title: 'Component type', | ||
type: 'array', | ||
choices: [ | ||
['h1', 'H1'], | ||
['h2', 'H2'], | ||
['h3', 'H3'], | ||
['p', 'Paragraph'], | ||
], | ||
}, | ||
}; | ||
}; | ||
|
||
const Edit = (props) => { | ||
const [state, setState] = useState({ | ||
schema: getSchema({ ...props, providerUrl: settings.providerUrl }), | ||
id: _uniqueId('block_'), | ||
}); | ||
return ( | ||
<div> | ||
<RenderFields | ||
schema={state.schema} | ||
{...props} | ||
title="Query param text block" | ||
noValueKey={true} | ||
/> | ||
<View {...props} id={state.id} mode="edit" /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
pathname: state.router.location.pathname, | ||
})), | ||
)(Edit); |
78 changes: 78 additions & 0 deletions
78
src/components/manage/Blocks/DiscodataComponents/Link/View.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,78 @@ | ||
/* REACT */ | ||
import React, { useState } from 'react'; | ||
import { compose } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
|
||
function isColor(strColor) { | ||
return /^#[0-9A-F]{6}$/i.test(strColor); | ||
} | ||
|
||
const components = { | ||
h1: (text, color) => ( | ||
<h1 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h1> | ||
), | ||
h2: (text, color) => ( | ||
<h2 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h2> | ||
), | ||
h3: (text, color) => ( | ||
<h3 className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</h3> | ||
), | ||
p: (text, color) => ( | ||
<p className="query-param-text" style={{ color: color }}> | ||
{text} | ||
</p> | ||
), | ||
}; | ||
|
||
const View = ({ content, ...props }) => { | ||
const { data } = props; | ||
const { | ||
visible = 'always', | ||
component = 'h1', | ||
queryParam = '', | ||
leftText = '', | ||
rightText = '', | ||
color = '#000', | ||
} = data; | ||
|
||
const queryText = props.search[queryParam] || ''; | ||
|
||
const text = `${leftText} ${queryText} ${rightText}`; | ||
|
||
const hasText = leftText || queryText || rightText; | ||
|
||
const textMayRender = | ||
(visible === 'always' && hasText) || (visible === 'hasQuery' && queryText); | ||
|
||
return ( | ||
<> | ||
{props.mode === 'edit' ? ( | ||
!textMayRender ? ( | ||
<p>Query param text</p> | ||
) : ( | ||
'' | ||
) | ||
) : ( | ||
'' | ||
)} | ||
{textMayRender && components[component] | ||
? components[component](text, isColor(color) ? color : '#000') | ||
: ''} | ||
</> | ||
); | ||
}; | ||
|
||
export default compose( | ||
connect((state, props) => ({ | ||
query: state.router.location.search, | ||
content: | ||
state.prefetch?.[state.router.location.pathname] || state.content.data, | ||
search: state.discodata_query.search, | ||
})), | ||
)(View); |
Oops, something went wrong.