Skip to content

Commit

Permalink
feat(base): add a variant of change indicator for relative paths with…
Browse files Browse the repository at this point in the history
… passed isChanged value
  • Loading branch information
bjoerge committed Apr 26, 2021
1 parent afad1b8 commit 1d7c1ae
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion packages/@sanity/base/src/change-indicators/ChangeIndicator.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useLayer} from '@sanity/ui'
import React, {memo, useMemo} from 'react'
import React, {memo, ReactNode, useMemo} from 'react'
import deepCompare from 'react-fast-compare'
import * as PathUtils from '@sanity/util/paths'
import {Path} from '@sanity/types'
Expand Down Expand Up @@ -160,6 +160,41 @@ export const CoreChangeIndicator = ({
)
}

export const ChangeIndicatorForFieldPath = ({
className,
disabled,
path,
hasFocus,
isChanged,
children,
}: {
path: Path
isChanged: boolean
children: ReactNode
className?: string
disabled?: boolean
hasFocus?: boolean
}) => {
const parentContext = React.useContext(ChangeIndicatorContext)

const fullPath = React.useMemo(() => parentContext.fullPath.concat(path), [
parentContext.fullPath,
path,
])

return (
<ChangeBarWrapper
disabled={disabled}
className={className}
isChanged={isChanged}
hasFocus={Boolean(hasFocus)}
fullPath={fullPath}
>
{children}
</ChangeBarWrapper>
)
}

export const ChangeIndicatorWithProvidedFullPath = ({
className,
disabled,
Expand Down

0 comments on commit 1d7c1ae

Please sign in to comment.