
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@nrk/sanity-plugin-nrkno-odd-utils
Advanced tools
_This lib expands on the [principles of nrkno-sanity](https://github.com/nrkno/nrkno-sanity-libs/blob/master/docs/nrkno-sanity-principles.md)._
This lib expands on the principles of nrkno-sanity.
nrkno-odd-utils (odd = option driven design) contains a handful of utility functions and classes for working with Sanity custom components.
See docs about option driven design for more.
yarn add @nrk/sanity-plugin-nrkno-odd-utils
npm install --save @nrk/sanity-plugin-nrkno-odd-utils
Easily decorate and reuse built-in Sanity inputs by delegating to NestedFormBuilder. It is imperative that we unset the inputComponent in the type (or unset the option used by input-resolver.ts).
Functions available as module imports:
import {
unsetOption,
unsetInputComponent,
useUnsetOption,
useUnsetInputComponent,
NestedFormBuilder
} from '@nrk/sanity-plugin-nrkno-odd-utils'
Given a schema with an input component:
const schemaOrField = {
name: 'schemaOrField',
inputComponent: CustomComponent,
}
We can decorate a custom heading over a standard sanity input (regardless of type), like so:
// CustomComponent.tsx
import React, {forwardRef, Ref} from 'react';
import {useUnsetInputComponent, NestedFormBuilder} from '@nrk/sanity-plugin-nrkno-odd-utils';
export const CustomComponent = forwardRef(function CustomComponent(props, ref) {
// IMPORTANT: leaving out will cause the browser to lock up in an infinite loop
const type = useUnsetInputComponent(props.type);
return <div>
<h4>A custom heading</h4>
<NestedFormBuilder {...props} ref={ref} type={type}/>
</div>;
});
Given a schema with an option, and an input-resolver.js file defined in sanity.json:
// schema-file.js
const schemaOrField = {
name: 'schemaOrField',
option: {
custom: true
}
}
// input-resolver.js
function resolveInput(schema) {
if(schema.options?.custom) {
return CustomComponent
}
}
We can decorate a custom heading over a standard sanity input (regardless of type), like so:
// CustomComponent.tsx
import React, {forwardRef, Ref} from 'react';
import {useUnsetOption, NestedFormBuilder} from '@nrk/sanity-plugin-nrkno-odd-utils';
export const CustomComponent = forwardRef(function CustomComponent(props, ref) {
// IMPORTANT: leaving out will cause the browser to lock up in an infinite loop
const type = useUnsetOption(props.type, 'custom');
return <div>
<h4>A custom heading</h4>
<NestedFormBuilder {...props} ref={ref} type={type}/>
</div>;
});
NestedFormBuilder extends FormBuilderInput. FormBuilderInput is a Sanity component that uses
non-standard import syntax that does not play well with Jest (import x from 'part:xyz'
).
See NestedFormBuilder.test.ts for examples on how to mock FormBuilderInput, and check which props passed to FormBuilderInput during render.
This is useful when unit-testing that props.type was modified correctly for instance.
This plugin is built with sanipack.
Inside this directory run
npm run build
yarn link
Then
cd /path/to/sanity-studio
yarn link @nrk/sanity-plugin-nrkno-odd-utils
The change to yarn is intentional , since that is what Sanity Studio uses.
FAQs
_This lib expands on the [principles of nrkno-sanity](https://github.com/nrkno/nrkno-sanity-libs/blob/master/docs/nrkno-sanity-principles.md)._
The npm package @nrk/sanity-plugin-nrkno-odd-utils receives a total of 132 weekly downloads. As such, @nrk/sanity-plugin-nrkno-odd-utils popularity was classified as not popular.
We found that @nrk/sanity-plugin-nrkno-odd-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 150 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.