Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop mui #897

Merged
merged 28 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9b9d6b6
Mui removed and basic functionality implemented
forgetso Dec 8, 2023
6d3a93f
Put it in working state
forgetso Dec 8, 2023
48542e0
button styles
forgetso Dec 8, 2023
9c9b710
Fix modal styling
forgetso Dec 8, 2023
62d962f
Button component
forgetso Dec 8, 2023
79a6df1
Change checkbox selector
forgetso Dec 8, 2023
256c218
Add hover styles to buttons
forgetso Dec 8, 2023
f1f2303
Merge branch 'main' into drop-mui
forgetso Dec 8, 2023
cdfbcc2
bot suggestion
forgetso Dec 8, 2023
389314e
Add package-lock.json back in
forgetso Dec 8, 2023
c05d7cc
switch span to p
forgetso Dec 8, 2023
489d176
Add dev data tags
forgetso Dec 8, 2023
9d885a7
preventDefault
forgetso Dec 8, 2023
ba7c3ed
Fix web3 select box
forgetso Dec 11, 2023
bab1004
Correct svg attr
forgetso Dec 11, 2023
b689e5f
min and max width, margin
forgetso Dec 11, 2023
efffb13
Merge branch 'main' into drop-mui
forgetso Dec 11, 2023
ccb9b9d
Make checkbox component. Address Hugh's review points
forgetso Dec 11, 2023
ae71899
Merge branch 'main' into drop-mui
forgetso Dec 11, 2023
d33a6ea
lint:fix
forgetso Dec 11, 2023
fde9443
Add mode descriptive URL in widget
forgetso Dec 12, 2023
0a0627d
Merge branch 'main' into drop-mui
forgetso Dec 12, 2023
875305f
lint:fix
forgetso Dec 12, 2023
d377203
Merge branch 'main' into drop-mui
forgetso Dec 12, 2023
6c4cc31
lint:fix
forgetso Dec 12, 2023
f1f56ae
Merge branch 'main' into drop-mui
forgetso Dec 12, 2023
77f3196
Merge branch 'main' into drop-mui
forgetso Dec 12, 2023
1018453
Merge branch 'main' into drop-mui
HughParry Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/cypress-shared/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare global {
}
}

export const checkboxClass = '.PrivateSwitchBase-input'
export const checkboxClass = '[type="checkbox"]'
function clickIAmHuman(): Cypress.Chainable<Captcha[]> {
cy.intercept('GET', '**/prosopo/provider/captcha/**').as('getCaptcha')
cy.get(checkboxClass, { timeout: 12000 }).first().click()
Expand Down
2,413 changes: 2,297 additions & 116 deletions package-lock.json

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions packages/procaptcha-react/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { darkTheme, lightTheme } from './theme.js'
import React, { ButtonHTMLAttributes, CSSProperties, useMemo, useState } from 'react'
import addDataAttr from '../util/index.js'

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
themeColor: 'light' | 'dark'
buttonType: 'cancel' | 'next'
onClick: () => void
text: string
}

const buttonStyleBase: CSSProperties = {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
boxSizing: 'border-box',
outline: '0px',
border: '0px',
margin: '0px',
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
appearance: undefined,
textDecoration: 'none',
fontWeight: '500',
fontSize: '0.875rem',
lineHeight: '1.75',
letterSpacing: '0.02857em',
textTransform: 'uppercase',
minWidth: '64px',
padding: '6px 16px',
borderRadius: '4px',
transition:
'background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
color: 'rgb(0, 0, 0)',
backgroundColor: '#ffffff',
boxShadow:
'rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px',
}

const Button: React.FC<ButtonProps> = ({ themeColor, buttonType, text, onClick }: ButtonProps) => {
const theme = useMemo(() => (themeColor === 'light' ? lightTheme : darkTheme), [themeColor])
const [hover, setHover] = useState(false)
const buttonStyle = useMemo(() => {
const baseStyle = {
...buttonStyleBase,
color: hover ? theme.palette.primary.contrastText : theme.palette.background.contrastText,
}
if (buttonType === 'cancel') {
return {
...baseStyle,
backgroundColor: hover ? theme.palette.grey[600] : 'transparent',
}
} else {
return {
...baseStyle,
backgroundColor: hover ? theme.palette.primary.main : theme.palette.background.default,
}
}
}, [buttonType, hover, theme])

return (
<button
{...addDataAttr({ dev: { cy: `button-${buttonType}` } })}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
style={buttonStyle}
onClick={(e) => {
e.preventDefault()
onClick()
}}
>
{text}
</button>
)
}
export default Button
101 changes: 57 additions & 44 deletions packages/procaptcha-react/src/components/CaptchaComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Box, Button, Typography } from '@mui/material'
import { CaptchaWidget } from './CaptchaWidget.js'
import { GetCaptchaResponse } from '@prosopo/api'
import { at } from '@prosopo/util'
import { darkTheme, lightTheme } from './theme.js'
import { useMemo } from 'react'
import { useTranslation } from '@prosopo/common'
import Button from './Button.js'
import addDataAttr from '../util/index.js'

export interface CaptchaComponentProps {
Expand Down Expand Up @@ -47,93 +47,106 @@ const CaptchaComponent = ({
const theme = useMemo(() => (themeColor === 'light' ? lightTheme : darkTheme), [themeColor])

return (
<Box
sx={{
<div
style={{
// introduce scroll bars when screen < minWidth of children
overflowX: 'auto',
overflowY: 'auto',
width: '100%',
maxWidth: '500px',
maxHeight: '100%',
display: 'flex',
flexDirection: 'column',
}}
>
<Box
bgcolor={theme.palette.background.default}
sx={{
<div
style={{
backgroundColor: theme.palette.background.default,
display: 'flex',
flexDirection: 'column',
minWidth: '300px',
}}
>
<Box
px={2}
py={3}
sx={{
<div
style={{
display: 'flex',
alignItems: 'center',
width: '100%',
backgroundColor: theme.palette.primary.main,
padding: '24px 16px',
}}
bgcolor={theme.palette.primary.main}
>
<Typography
sx={{
<p
style={{
color: '#ffffff',
fontWeight: 700,
lineHeight: 1.5,
}}
>
{t('WIDGET.SELECT_ALL')}
{': '}
</Typography>
<Typography
px={1}
sx={{
</p>
<p
style={{
color: '#ffffff',
fontWeight: 700,
textTransform: 'capitalize',
fontSize: theme.typography.h6.fontSize,
lineHeight: 1.5,
}}
>
{`${at(challenge.captchas, index).captcha.target}`}
</Typography>
</Box>
<Box {...addDataAttr({ dev: { cy: 'captcha-' + index } })}>
{captcha && <CaptchaWidget challenge={captcha} solution={solution} onClick={onClick} />}
</Box>
<Box
px={2}
py={1}
sx={{
</p>
</div>
<div {...addDataAttr({ dev: { cy: 'captcha-' + index } })}>
{captcha && (
<CaptchaWidget
challenge={captcha}
solution={solution}
onClick={onClick}
themeColor={themeColor}
/>
)}
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
}}
{...addDataAttr({ dev: { cy: 'dots-captcha' } })}
/>
<Box
px={2}
pt={0}
pb={2}
sx={{
<div
style={{
padding: '8px 16px',
display: 'flex',
width: '100%',
}}
></div>
<div
style={{
padding: '0 16px 16px',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
lineHeight: 1.75,
}}
>
<Button onClick={onCancel} variant="text">
{t('WIDGET.CANCEL')}
</Button>
<Button
color="primary"
themeColor={themeColor}
buttonType="cancel"
onClick={onCancel}
text={t('WIDGET.CANCEL')}
></Button>
<Button
themeColor={themeColor}
buttonType="next"
text={index < challenge.captchas.length - 1 ? t('WIDGET.NEXT') : t('WIDGET.SUBMIT')}
onClick={index < challenge.captchas.length - 1 ? onNext : onSubmit}
variant="contained"
{...addDataAttr({ dev: { cy: 'button-next' } })}
>
{index < challenge.captchas.length - 1 ? t('WIDGET.NEXT') : t('WIDGET.SUBMIT')}
</Button>
</Box>
</Box>
</Box>
></Button>
</div>
</div>
</div>
)
}

Expand Down
Loading
Loading